Author: emuckenhuber
Date: 2007-10-17 11:08:55 -0400 (Wed, 17 Oct 2007)
New Revision: 8683
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/JUnitReporterTests.java
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitReporter.java
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitTestReport.java
Log:
- display also the class name in the testcase name
- fixed the testcase time (now in seconds instead of milliseconds)
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/JUnitReporterTests.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/JUnitReporterTests.java 2007-10-17
13:58:54 UTC (rev 8682)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/report/junit/JUnitReporterTests.java 2007-10-17
15:08:55 UTC (rev 8683)
@@ -53,6 +53,7 @@
testTestSuite();
testTestCase();
testTestCaseFailure();
+ testTestCaseClass();
}
private static void testTestSuite()
@@ -89,7 +90,10 @@
Assert.assertEquals("fehler", error.getAttribute(ATTR_MESSAGE));
}
-
+ /**
+ * Successful testCase
+ *
+ */
private static void testTestCase()
{
MyTestReport report = new MyTestReport(testSuiteName);
@@ -114,11 +118,48 @@
Element testCase = child(e, TESTCASE);
Assert.assertEquals(TESTCASE, testCase.getNodeName());
Assert.assertEquals("foo", testCase.getAttribute(ATTR_NAME));
- Assert.assertEquals("20", testCase.getAttribute(ATTR_TIME));
+ Assert.assertEquals("0.02", testCase.getAttribute(ATTR_TIME));
Assert.assertNull(child(e, ERROR));
}
+ /**
+ * Successful testCase with class info
+ *
+ */
+ private static void testTestCaseClass()
+ {
+ MyTestReport report = new MyTestReport(testSuiteName);
+ report.startTestSuite(new StartRunnerEvent());
+
+ // Set current tested class name
+ report.setCurrentTestedClassName("org.jboss.portal.test.testedClass1");
+
+ TestId testId = new TestId("foo");
+ StartTestCaseEvent startTestEvent = new StartTestCaseEvent(testId, new
MyTestInfo());
+ report.startTest(startTestEvent);
+
+ TestResult testResult = new TestSuccess(20);
+ EndTestCaseEvent endTestEvent = new EndTestCaseEvent(testId, testResult);
+ report.endTest(endTestEvent);
+ // end report
+ report.endTestSuite(new EndRunnerEvent());
+ Element e = report.getRootElement();
+
+ Assert.assertEquals(TESTSUITE, e.getNodeName());
+ Assert.assertEquals("1", e.getAttribute(ATTR_TESTS));
+ Assert.assertEquals("0", e.getAttribute(ATTR_ERRORS));
+ Assert.assertEquals("0", e.getAttribute(ATTR_FAILURES));
+
+ Element testCase = child(e, TESTCASE);
+ Assert.assertEquals(TESTCASE, testCase.getNodeName());
+ Assert.assertEquals("org.jboss.portal.test.testedClass1.foo",
testCase.getAttribute(ATTR_NAME));
+ Assert.assertEquals("0.02", testCase.getAttribute(ATTR_TIME));
+
+ Assert.assertNull(child(e, ERROR));
+ }
+
+
private static void testTestCaseFailure()
{
MyTestReport report = new MyTestReport(testSuiteName);
@@ -144,7 +185,7 @@
Element testCase = child(e, TESTCASE);
Assert.assertEquals(TESTCASE, testCase.getNodeName());
Assert.assertEquals("foo", testCase.getAttribute(ATTR_NAME));
- Assert.assertEquals("20", testCase.getAttribute(ATTR_TIME));
+ Assert.assertEquals("0.02", testCase.getAttribute(ATTR_TIME));
Element error = child(testCase, FAILURE);
Assert.assertEquals("expecting something different.",
error.getAttribute(ATTR_MESSAGE));
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitReporter.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitReporter.java 2007-10-17
13:58:54 UTC (rev 8682)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitReporter.java 2007-10-17
15:08:55 UTC (rev 8683)
@@ -34,6 +34,7 @@
import org.jboss.unit.runner.event.RunnerFailureEvent;
import org.jboss.unit.runner.event.StartRunnerEvent;
import org.jboss.unit.runner.event.StartTestCaseEvent;
+import org.jboss.unit.runner.event.StartTestSuiteEvent;
/**
*
@@ -99,6 +100,10 @@
{
report.runnerFailed((RunnerFailureEvent) event);
}
+ else if (event instanceof StartTestSuiteEvent)
+ {
+ report.setCurrentTestedClassName(((StartTestSuiteEvent)
event).getTestInfo().getName());
+ }
else if (event instanceof StartTestCaseEvent)
{
report.startTest((StartTestCaseEvent) event);
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-17
13:58:54 UTC (rev 8682)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/report/impl/junit/JUnitTestReport.java 2007-10-17
15:08:55 UTC (rev 8683)
@@ -30,6 +30,7 @@
import java.io.Writer;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
@@ -58,6 +59,7 @@
import org.jboss.unit.runner.event.RunnerFailureEvent;
import org.jboss.unit.runner.event.StartRunnerEvent;
import org.jboss.unit.runner.event.StartTestCaseEvent;
+import org.jboss.unit.runner.event.StartTestSuiteEvent;
import org.jboss.unit.runner.results.TestFailure;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -100,8 +102,14 @@
/** The failed count */
private int failed;
+ /** The timeStamp */
private String timeStamp;
+
+ /** The current testSuiteName */
+ private String currentTestedClassName;
+ /** .*/
+ private NumberFormat FORMAT = NumberFormat.getInstance();
public JUnitTestReport()
{
@@ -129,6 +137,11 @@
*/
}
+ public void setCurrentTestedClassName(String testedClassName)
+ {
+ this.currentTestedClassName = testedClassName;
+ }
+
public void startTest(StartTestCaseEvent event)
{
this.startedTests.put(event.getTestId(), event.getTestInfo());
@@ -156,6 +169,13 @@
Element test = document.createElement(XMLConstants.TESTCASE);
/** The testcase name */
StringBuffer nb = new StringBuffer();
+ /** The current tested Class */
+ if (this.currentTestedClassName != null)
+ {
+ nb.append(this.currentTestedClassName);
+ nb.append(".");
+ }
+ /** TestId */
for(int i = 0; i < testId.getLength(); i ++)
{
if (i > 0)
@@ -165,6 +185,7 @@
nb.append(testId.getName(i));
}
String testName = nb.toString();
+
/** The testcase parameters */
StringBuffer parameters = new StringBuffer();
for(Iterator<String> i = result.getParametrization().keySet().iterator();
i.hasNext(); )
@@ -181,9 +202,10 @@
if ( parameters.length() > 0)
testName = testName + "?" + parameters.toString();
+
/** Test case attributes */
test.setAttribute(XMLConstants.ATTR_NAME, testName);
- test.setAttribute(XMLConstants.ATTR_TIME, new
Long(result.getDurationMillis()).toString());
+ test.setAttribute(XMLConstants.ATTR_TIME, FORMAT.format(result.getDurationMillis()
/ 1000.0));
/** Check if test was started */
TestInfo info = this.startedTests.get(testId);
if ( info != null)