Author: jaz
Date: Tue Jun 19 08:25:41 2007 New Revision: 548763 URL: http://svn.apache.org/viewvc?view=rev&rev=548763 Log: updated test running to log more details about junit tests, also added new option -case=name-of-case to run just a specifc test-case. java -jar ofbiz.jar -test -component=[componentName] -case=[caseName] Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java?view=diff&rev=548763&r1=548762&r2=548763 ============================================================================== --- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java (original) +++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java Tue Jun 19 08:25:41 2007 @@ -41,19 +41,24 @@ protected List modelTestSuiteList = FastList.newInstance(); - public JunitSuiteWrapper(String componentName) { + public JunitSuiteWrapper(String componentName, String testCase) { List testSuiteInfoList = ComponentConfig.getAllTestSuiteInfos(componentName); Iterator testSuiteInfoIter = testSuiteInfoList.iterator(); while (testSuiteInfoIter.hasNext()) { ComponentConfig.TestSuiteInfo testSuiteInfo = (ComponentConfig.TestSuiteInfo) testSuiteInfoIter.next(); - ResourceHandler testSuiteResource = testSuiteInfo.createResourceHandler(); + try { Document testSuiteDocument = testSuiteResource.getDocument(); // TODO create TestSuite object based on this that will contain its TestCase objects + Element documentElement = testSuiteDocument.getDocumentElement(); - ModelTestSuite modelTestSuite = new ModelTestSuite(documentElement); - this.modelTestSuiteList.add(modelTestSuite); + ModelTestSuite modelTestSuite = new ModelTestSuite(documentElement, testCase); + + // make sure there are test-cases configured for the suite + if (modelTestSuite.getTestList().size() > 0) { + this.modelTestSuiteList.add(modelTestSuite); + } } catch (GenericConfigException e) { String errMsg = "Error reading XML document from ResourceHandler for loader [" + testSuiteResource.getLoaderName() + "] and location [" + testSuiteResource.getLocation() + "]"; Debug.logError(e, errMsg, module); Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java?view=diff&rev=548763&r1=548762&r2=548763 ============================================================================== --- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java (original) +++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java Tue Jun 19 08:25:41 2007 @@ -50,8 +50,8 @@ protected LocalDispatcher dispatcher; protected List testList = FastList.newInstance(); - - public ModelTestSuite(Element mainElement) { + + public ModelTestSuite(Element mainElement, String testCase) { this.suiteName = mainElement.getAttribute("suite-name"); this.delegatorName = mainElement.getAttribute("delegator-name"); @@ -68,38 +68,39 @@ while (testCaseElementIter.hasNext()) { Element testCaseElement = (Element) testCaseElementIter.next(); String caseName = testCaseElement.getAttribute("case-name"); - - Element childElement = UtilXml.firstChildElement(testCaseElement); - String nodeName = childElement.getNodeName(); - if ("junit-test-suite".equals(nodeName)) { - String className = childElement.getAttribute("class-name"); + if (testCase == null || caseName.equals(testCase)) { + Element childElement = UtilXml.firstChildElement(testCaseElement); + String nodeName = childElement.getNodeName(); + if ("junit-test-suite".equals(nodeName)) { + String className = childElement.getAttribute("class-name"); - try { - Class clz = ObjectType.loadClass(className); - TestSuite suite = new TestSuite(); - suite.addTestSuite(clz); - Enumeration testEnum = suite.tests(); - int testsAdded = 0; - int casesAdded = 0; - while (testEnum.hasMoreElements()) { - Test tst = (Test) testEnum.nextElement(); - this.testList.add(tst); - casesAdded += tst.countTestCases(); - testsAdded++; + try { + Class clz = ObjectType.loadClass(className); + TestSuite suite = new TestSuite(); + suite.addTestSuite(clz); + Enumeration testEnum = suite.tests(); + int testsAdded = 0; + int casesAdded = 0; + while (testEnum.hasMoreElements()) { + Test tst = (Test) testEnum.nextElement(); + this.testList.add(tst); + casesAdded += tst.countTestCases(); + testsAdded++; + } + Debug.logInfo("Added " + testsAdded + " tests [" + casesAdded + " cases] from the class: " + className, module); + } catch (Exception e) { + String errMsg = "Unable to load test suite class : " + className; + Debug.logError(e, errMsg, module); } - Debug.logInfo("Added " + testsAdded + " tests [" + casesAdded + " cases] from the class: " + className, module); - } catch (Exception e) { - String errMsg = "Unable to load test suite class : " + className; - Debug.logError(e, errMsg, module); + } else if ("service-test".equals(nodeName)) { + this.testList.add(new ServiceTest(caseName, this, childElement)); + } else if ("simple-method-test".equals(nodeName)) { + this.testList.add(new SimpleMethodTest(caseName, this, childElement)); + } else if ("entity-xml-assert".equals(nodeName)) { + this.testList.add(new EntityXmlAssertTest(caseName, this, childElement)); + } else if ("jython-test".equals(nodeName)) { + this.testList.add(new JythonTest(caseName, this, childElement)); } - } else if ("service-test".equals(nodeName)) { - this.testList.add(new ServiceTest(caseName, this, childElement)); - } else if ("simple-method-test".equals(nodeName)) { - this.testList.add(new SimpleMethodTest(caseName, this, childElement)); - } else if ("entity-xml-assert".equals(nodeName)) { - this.testList.add(new EntityXmlAssertTest(caseName, this, childElement)); - } else if ("jython-test".equals(nodeName)) { - this.testList.add(new JythonTest(caseName, this, childElement)); } } } Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java?view=diff&rev=548763&r1=548762&r2=548763 ============================================================================== --- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java (original) +++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java Tue Jun 19 08:25:41 2007 @@ -20,8 +20,7 @@ import java.util.Enumeration; -import junit.framework.TestResult; -import junit.framework.TestSuite; +import junit.framework.*; import org.ofbiz.base.container.Container; import org.ofbiz.base.container.ContainerException; @@ -36,6 +35,7 @@ protected TestResult results = null; protected String configFile = null; protected String component = null; + protected String testCase = null; /** * @see org.ofbiz.base.container.Container#init(java.lang.String[], java.lang.String) @@ -62,6 +62,9 @@ if ("component".equalsIgnoreCase(argumentName)) { this.component = argumentVal; } + if ("case".equalsIgnoreCase(argumentName)) { + this.testCase = argumentVal; + } } } } @@ -71,7 +74,10 @@ //ContainerConfig.Container jc = ContainerConfig.getContainer("junit-container", configFile); // get the tests to run - JunitSuiteWrapper jsWrapper = new JunitSuiteWrapper(component); + JunitSuiteWrapper jsWrapper = new JunitSuiteWrapper(component, testCase); + if (jsWrapper.getAllTestList().size() == 0) { + throw new ContainerException("No tests found (" + component + " / " + testCase + ")"); + } // load the tests into the suite TestSuite suite = new TestSuite(); @@ -79,6 +85,7 @@ // holder for the results results = new TestResult(); + results.addListener(new JunitListener()); // run the tests suite.run(results); @@ -117,6 +124,25 @@ Thread.sleep(2000); } catch (Exception e) { throw new ContainerException(e); + } + } + + class JunitListener implements TestListener { + + public void addError(Test test, Throwable throwable) { + Debug.logWarning("[JUNIT (error)] - " + test.getClass().getName() + " : " + throwable.getMessage(), module); + } + + public void addFailure(Test test, AssertionFailedError assertionFailedError) { + Debug.logWarning("[JUNIT (failure)] - " + test.getClass().getName() + " : " + assertionFailedError.getMessage(), module); + } + + public void endTest(Test test) { + Debug.logInfo("[JUNIT] : " + test.getClass().getName() + " finished.", module); + } + + public void startTest(Test test) { + Debug.logInfo("[JUNIT] : " + test.getClass().getName() + " starting...", module); } } } |
Free forum by Nabble | Edit this page |