Browse Source

Stefan pointed out that the XML formatter was mistakenly using "JUnit4TestFacade"

as the "class name" for simple TestCase's run under JUnit 4.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@411044 13f79535-47bb-0310-9956-ffa450edef68
master
Jesse N. Glick 19 years ago
parent
commit
6cd3b1f7a0
2 changed files with 19 additions and 1 deletions
  1. +18
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java
  2. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java

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

@@ -93,4 +93,22 @@ public class JUnitVersionHelper {
return "unknown";
}

/**
* Tries to find the name of the class which a test represents
* across JUnit 3 and 4.
*/
static String getTestCaseClassName(Test test) {
String className = test.getClass().getName();
if (className.equals("junit.framework.JUnit4TestCaseFacade")) {
// JUnit 4 wraps solo tests this way. We can extract
// the original test name with a little hack.
String name = test.toString();
int paren = name.lastIndexOf('(');
if (paren != -1 && name.endsWith(")")) {
className = name.substring(paren + 1, name.length() - 1);
}
}
return className;
}

}

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

@@ -200,7 +200,7 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
// a TestSuite can contain Tests from multiple classes,
// even tests with the same name - disambiguate them.
currentTest.setAttribute(ATTR_CLASSNAME,
test.getClass().getName());
JUnitVersionHelper.getTestCaseClassName(test));
rootElement.appendChild(currentTest);
testElements.put(test, currentTest);
} else {


Loading…
Cancel
Save