Browse Source

The xml formatter for JUnit will now honor test case names set with

setName

PR: 17040


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274340 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
96e6561e65
2 changed files with 21 additions and 11 deletions
  1. +3
    -0
      WHATSNEW
  2. +18
    -11
      src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java

+ 3
- 0
WHATSNEW View File

@@ -195,6 +195,9 @@ Other changes:
* Copy has a new outputencoding attribute that can be used to change * Copy has a new outputencoding attribute that can be used to change
the encoding while copying files. Bugzilla Report 18217. the encoding while copying files. Bugzilla Report 18217.


* The xml formatter for JUnit will now honor test case names set with
setName. Bugzilla Report 17040.

Changes from Ant 1.5.2 to Ant 1.5.3 Changes from Ant 1.5.2 to Ant 1.5.3
=================================== ===================================




+ 18
- 11
src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -103,6 +103,10 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* Element for the current test. * Element for the current test.
*/ */
private Hashtable testElements = new Hashtable(); private Hashtable testElements = new Hashtable();
/**
* tests that failed.
*/
private Hashtable failedTests = new Hashtable();
/** /**
* Timing helper. * Timing helper.
*/ */
@@ -186,12 +190,6 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
*/ */
public void startTest(Test t) { public void startTest(Test t) {
testStarts.put(t, new Long(System.currentTimeMillis())); testStarts.put(t, new Long(System.currentTimeMillis()));

Element currentTest = doc.createElement(TESTCASE);
currentTest.setAttribute(ATTR_NAME,
JUnitVersionHelper.getTestCaseName(t));
rootElement.appendChild(currentTest);
testElements.put(t, currentTest);
} }


/** /**
@@ -200,16 +198,24 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* <p>A Test is finished. * <p>A Test is finished.
*/ */
public void endTest(Test test) { public void endTest(Test test) {
Element currentTest = (Element) testElements.get(test);
// Fix for bug #5637 - if a junit.extensions.TestSetup is // Fix for bug #5637 - if a junit.extensions.TestSetup is
// used and throws an exception during setUp then startTest // used and throws an exception during setUp then startTest
// would never have been called // would never have been called
if (currentTest == null) {
if (!testStarts.containsKey(test)) {
startTest(test); startTest(test);
}

Element currentTest = null;
if (!failedTests.containsKey(test)) {
currentTest = doc.createElement(TESTCASE);
currentTest.setAttribute(ATTR_NAME,
JUnitVersionHelper.getTestCaseName(test));
rootElement.appendChild(currentTest);
testElements.put(test, currentTest);
} else {
currentTest = (Element) testElements.get(test); currentTest = (Element) testElements.get(test);
} }
Long l = (Long) testStarts.get(test); Long l = (Long) testStarts.get(test);
currentTest.setAttribute(ATTR_TIME, currentTest.setAttribute(ATTR_TIME,
"" + ((System.currentTimeMillis() - l.longValue()) / 1000.0)); "" + ((System.currentTimeMillis() - l.longValue()) / 1000.0));
@@ -245,6 +251,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
private void formatError(String type, Test test, Throwable t) { private void formatError(String type, Test test, Throwable t) {
if (test != null) { if (test != null) {
endTest(test); endTest(test);
failedTests.put(test, test);
} }


Element nested = doc.createElement(type); Element nested = doc.createElement(type);


Loading…
Cancel
Save