You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/09/18 06:27:16 UTC
svn commit: r576686 - in /ofbiz/trunk/framework: base/lib/ant-junit.jar
testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java
testtools/src/org/ofbiz/testtools/TestRunContainer.java
Author: jaz
Date: Mon Sep 17 21:27:14 2007
New Revision: 576686
URL: http://svn.apache.org/viewvc?rev=576686&view=rev
Log:
implemented junit xml formatted output to test cases; new options -results=filename default file outputs to runtime/logs/test-junit.xml
Added:
ofbiz/trunk/framework/base/lib/ant-junit.jar (with props)
Modified:
ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java
ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java
Added: ofbiz/trunk/framework/base/lib/ant-junit.jar
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/lib/ant-junit.jar?rev=576686&view=auto
==============================================================================
Binary file - no diff available.
Propchange: ofbiz/trunk/framework/base/lib/ant-junit.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
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?rev=576686&r1=576685&r2=576686&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java Mon Sep 17 21:27:14 2007
@@ -66,7 +66,8 @@
}
}
}
-
+
+ @Deprecated
public void populateTestSuite(TestSuite suite) {
Iterator modelTestSuiteIter = this.modelTestSuiteList.iterator();
while (modelTestSuiteIter.hasNext()) {
@@ -78,6 +79,26 @@
suite.addTest(tst);
}
}
+ }
+
+ public List makeTestSuites() {
+ List testSuites = FastList.newInstance();
+
+ Iterator modelTestSuiteIter = this.modelTestSuiteList.iterator();
+ while (modelTestSuiteIter.hasNext()) {
+ ModelTestSuite modelTestSuite = (ModelTestSuite) modelTestSuiteIter.next();
+ TestSuite suite = new TestSuite();
+ suite.setName(modelTestSuite.getSuiteName());
+ List testList = modelTestSuite.getTestList();
+ Iterator testIter = testList.iterator();
+ while (testIter.hasNext()) {
+ Test tst = (Test) testIter.next();
+ suite.addTest(tst);
+ }
+ testSuites.add(suite);
+ }
+
+ return testSuites;
}
public List getAllTestList() {
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?rev=576686&r1=576685&r2=576686&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java Mon Sep 17 21:27:14 2007
@@ -18,24 +18,34 @@
*******************************************************************************/
package org.ofbiz.testtools;
-import java.util.Enumeration;
-
+import javolution.util.FastMap;
import junit.framework.*;
-
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
+import org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter;
import org.ofbiz.base.container.Container;
import org.ofbiz.base.container.ContainerException;
import org.ofbiz.base.util.Debug;
+import java.io.*;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
/**
* A Container implementation to run the tests configured through this testtools stuff.
*/
public class TestRunContainer implements Container {
public static final String module = TestRunContainer.class.getName();
- protected TestResult results = null;
+ public static final String logFile = "runtime/logs/tests-junit.xml";
+
protected String configFile = null;
protected String component = null;
protected String testCase = null;
+ protected String outFile = null;
+ protected String logLevel = null;
/**
* @see org.ofbiz.base.container.Container#init(java.lang.String[], java.lang.String)
@@ -65,31 +75,66 @@
if ("case".equalsIgnoreCase(argumentName)) {
this.testCase = argumentVal;
}
+ if ("results".equalsIgnoreCase(argumentName)) {
+ this.outFile = argumentVal;
+ }
+ if ("loglevel".equalsIgnoreCase(argumentName)) {
+ this.logLevel = argumentVal;
+ }
}
}
}
}
public boolean start() throws ContainerException {
- //ContainerConfig.Container jc = ContainerConfig.getContainer("junit-container", configFile);
+ // configure log4j output logging
+ if (logLevel != null) {
+ int llevel = Debug.getLevelFromString(logLevel);
+
+ for (int v = 0; v < 9; v++) {
+ if (v < llevel) {
+ Debug.set(v, false);
+ } else {
+ Debug.set(v, true);
+ }
+ }
+ }
- // get the tests to run
- JunitSuiteWrapper jsWrapper = new JunitSuiteWrapper(component, testCase);
- if (jsWrapper.getAllTestList().size() == 0) {
- throw new ContainerException("No tests found (" + component + " / " + testCase + ")");
+ // configure xml output
+ if (outFile == null) {
+ outFile = logFile;
}
- // load the tests into the suite
- TestSuite suite = new TestSuite();
- jsWrapper.populateTestSuite(suite);
+ JunitXmlListener xml;
+ try {
+ xml = new JunitXmlListener(new FileOutputStream(outFile));
+ } catch (FileNotFoundException e) {
+ throw new ContainerException(e);
+ }
- // holder for the results
- results = new TestResult();
+ TestResult results = new TestResult();
results.addListener(new JunitListener());
+ results.addListener(xml);
- // run the tests
- suite.run(results);
+ // get the tests to run
+ JunitSuiteWrapper jsWrapper = new JunitSuiteWrapper(component, testCase);
+ if (jsWrapper.getAllTestList().size() == 0) {
+ throw new ContainerException("No tests found (" + component + " / " + testCase + ")");
+ }
+ List testSuites = jsWrapper.makeTestSuites();
+ Iterator i = testSuites.iterator();
+ while (i.hasNext()) {
+ TestSuite suite = (TestSuite) i.next();
+ JUnitTest test = new JUnitTest();
+ test.setName(suite.getName());
+ xml.startTestSuite(test);
+
+ // run the tests
+ suite.run(results);
+ xml.endTestSuite(test);
+ }
+
// dispay the results
Debug.log("[JUNIT] Pass: " + results.wasSuccessful() + " | # Tests: " + results.runCount() + " | # Failed: " +
results.failureCount() + " # Errors: " + results.errorCount(), module);
@@ -119,11 +164,26 @@
return true;
}
- public void stop() throws ContainerException {
- try {
- Thread.sleep(2000);
- } catch (Exception e) {
- throw new ContainerException(e);
+ public void stop() throws ContainerException {
+ }
+
+ class JunitXmlListener extends XMLJUnitResultFormatter {
+
+ Map<String, Long> startTimes = FastMap.newInstance();
+
+ public JunitXmlListener(OutputStream out) {
+ this.setOutput(out);
+ }
+
+ public void startTestSuite(JUnitTest suite) {
+ startTimes.put(suite.getName(), System.currentTimeMillis());
+ super.startTestSuite(suite);
+ }
+
+ public void endTestSuite(JUnitTest suite) throws BuildException {
+ long startTime = startTimes.get(suite.getName());
+ suite.setRunTime((System.currentTimeMillis() - startTime));
+ super.endTestSuite(suite);
}
}
@@ -138,11 +198,11 @@
}
public void endTest(Test test) {
- Debug.logInfo("[JUNIT] : " + test.getClass().getName() + " finished.", module);
+ //Debug.logInfo("[JUNIT] : " + test.getClass().getName() + " finished.", module);
}
public void startTest(Test test) {
- Debug.logInfo("[JUNIT] : " + test.getClass().getName() + " starting...", module);
+ //Debug.logInfo("[JUNIT] : " + test.getClass().getName() + " starting...", module);
}
}
}