Author: emuckenhuber
Date: 2007-10-10 11:34:37 -0400 (Wed, 10 Oct 2007)
New Revision: 8589
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitTestReport.java
Log:
- checking of TestCase Events
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitTestReport.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitTestReport.java 2007-10-10
14:53:42 UTC (rev 8588)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitTestReport.java 2007-10-10
15:34:37 UTC (rev 8589)
@@ -32,7 +32,9 @@
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -49,6 +51,7 @@
import org.jboss.unit.Failure;
import org.jboss.unit.FailureType;
import org.jboss.unit.TestId;
+import org.jboss.unit.info.TestInfo;
import org.jboss.unit.runner.TestResult;
import org.jboss.unit.runner.event.EndRunnerEvent;
import org.jboss.unit.runner.event.EndTestEvent;
@@ -72,9 +75,6 @@
public static final String DEFAULT_TEST_SUITE_NAME = "JBossUnitTestSuite";
public static final String TEST_FILE_NAME_START = "TEST-";
-
- /** The line separator */
- private final static String ls = System.getProperty("line.separator");
/** The document */
private Document document;
@@ -82,6 +82,9 @@
/** The root element */
private Element rootElement;
+ /** The started Tests */
+ private Map<TestId, TestInfo> startedTests = new HashMap<TestId,
TestInfo>();
+
/** The system error */
private StringBuffer systemErr = new StringBuffer();
@@ -112,28 +115,37 @@
public void startTestSuite(StartRunnerEvent event)
{
+ /** Create root element */
this.document = getDocumentBuilder().newDocument();
this.rootElement = this.document.createElement(XMLConstants.TESTSUITE);
this.rootElement.setAttribute(XMLConstants.TIMESTAMP, getTimestamp());
this.rootElement.setAttribute(XMLConstants.HOSTNAME, getHostName());
- this.rootElement.setAttribute(XMLConstants.ATTR_NAME, getTestSuiteName());
+ this.rootElement.setAttribute(XMLConstants.ATTR_NAME, this.testSuiteName);
+ /** Create properties element */
Element properties = document.createElement(XMLConstants.PROPERTIES);
this.rootElement.appendChild(properties);
- // add properties list
-
+ /**
+ * TODO - set properties
+ */
}
public void startTest(StartTestEvent event)
{
+ this.startedTests.put(event.getTestId(), event.getTestInfo());
this.tests++;
}
public void runnerFailed(RunnerFailureEvent event)
{
- this.tests++;
+ this.tests++;
this.errors++;
Element e = document.createElement(XMLConstants.ERROR);
- e.appendChild(document.createCDATASection(ls + event.getFailure().getMessage() + ls
+ stackToString(event.getFailure().getCause())));
+ e.setAttribute(XMLConstants.ATTR_TYPE, event.getFailure().getType().name());
+ e.setAttribute(XMLConstants.ATTR_MESSAGE, event.getFailure().getMessage());
+ if ( event.getFailure().getCause() != null)
+ {
+
e.appendChild(document.createCDATASection(stackToString(event.getFailure().getCause())));
+ }
rootElement.appendChild(e);
}
@@ -142,7 +154,7 @@
TestId testId = event.getTestId();
TestResult result = event.getTestResult();
Element test = document.createElement(XMLConstants.TESTCASE);
- // The test name
+ /** The testcase name */
StringBuffer nb = new StringBuffer();
for(int i = 0; i < testId.getLength(); i ++)
{
@@ -153,22 +165,41 @@
nb.append(testId.getName(i));
}
String testName = nb.toString();
- // Test parameters
+ /** The testcase parameters */
StringBuffer parameters = new StringBuffer();
- for(Iterator<String> i = result.getParametrization().values().iterator();
i.hasNext(); )
+ for(Iterator<String> i = result.getParametrization().keySet().iterator();
i.hasNext(); )
{
String name = i.next();
String value = result.getParametrization().get(name);
- parameters.append(name + "=" + value + "?");
+ parameters.append( name + "=" + value );
+ if(i.hasNext())
+ {
+ parameters.append("&");
+ }
}
-
+ // append parameters
if ( parameters.length() > 0)
testName = testName + "?" + parameters.toString();
+ /** Test case attributes */
test.setAttribute(XMLConstants.ATTR_NAME, testName);
- // Testcase time
test.setAttribute(XMLConstants.ATTR_TIME, new
Long(result.getDurationMillis()).toString());
- // If test failed
+ /** Check if test was started */
+ TestInfo info = this.startedTests.get(testId);
+ if ( info != null)
+ {
+ // remove test from started List
+ this.startedTests.remove(testId);
+ }
+ else
+ {
+ // If test is not started - add error message
+ Element errorNotStarted = document.createElement(XMLConstants.ERROR);
+ errorNotStarted.setAttribute(XMLConstants.ATTR_MESSAGE, "TestCase: " +
testName + " was not started properly. (No StartTestEvent)");
+ test.appendChild(errorNotStarted);
+ }
+
+ /** If testcase failed */
if (result instanceof TestFailure)
{
TestFailure testFailure = (TestFailure) result;
@@ -194,6 +225,16 @@
public void endTestSuite(EndRunnerEvent event)
{
+ if( this.startedTests.size() > 0 )
+ {
+ for(TestId id : this.startedTests.keySet())
+ {
+ Element errorNotEnded = document.createElement(XMLConstants.ERROR);
+ errorNotEnded.setAttribute(XMLConstants.ATTR_MESSAGE, "Testcase: "
+ id + " was not ended properly. (No EndTestEvent)");
+ this.rootElement.appendChild(errorNotEnded);
+ }
+ }
+
// Testsuite counts (tests, errors, failures)
this.rootElement.setAttribute(XMLConstants.ATTR_TESTS,
Integer.toString(this.tests));
this.rootElement.setAttribute(XMLConstants.ATTR_ERRORS,
Integer.toString(this.errors));
@@ -208,8 +249,6 @@
this.rootElement.appendChild(systemError);
this.rootElement.appendChild(systemOutElement);
-
- // System.out.println(exportXML());
}
public void appendSystemOutput(String output)
@@ -231,7 +270,7 @@
// If no test suite name is specified use default and add timestamp
filePath.append(toDir)
- .append("/")
+ .append(File.separator)
.append(TEST_FILE_NAME_START)
.append(getTestSuiteName())
.append(getTestSuiteName().equals(DEFAULT_TEST_SUITE_NAME) ? "-" +
getTimestamp() : "" )