Browse Source

subclasses of AssertionErrors are caused by test failures, not errors. PR 45028.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@704571 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
b8e3f831d6
2 changed files with 18 additions and 2 deletions
  1. +6
    -0
      WHATSNEW
  2. +12
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java

+ 6
- 0
WHATSNEW View File

@@ -247,6 +247,12 @@ Fixed bugs:
* MailLogger could cause a NullPointerException.
Bugzilla Report 44009.

* <junit> didn't recognize failed assertions as failures if they
caused subclasses of AssertionError to be thrown (like
org.junit.ComparisonFailure that is thrown when assertEquals
fails).
Bugzilla Report 45028.

Other changes:
--------------



+ 12
- 2
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java View File

@@ -976,7 +976,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
// even in the JUnit 3 adapter.
// So we need to help it a bit to retain compatibility for JUnit 3 tests.
testListener.addFailure(test, (AssertionFailedError) t);
} else if (junit4 && t.getClass().getName().equals("java.lang.AssertionError")) {
} else if (junit4 && isAssertionError(t.getClass())) {
// Not strictly necessary but probably desirable.
// JUnit 4-specific test GUIs will show just "failures".
// But Ant's output shows "failures" vs. "errors".
@@ -1035,7 +1035,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
while (e.hasMoreElements()) {
Throwable t = ((TestFailure) e.nextElement()).thrownException();
if (t instanceof AssertionFailedError
|| t.getClass().getName().equals("java.lang.AssertionError")) {
|| isAssertionError(t.getClass())) {
failures++;
} else {
errors++;
@@ -1044,4 +1044,14 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
return new int[] {failures, errors};
}

private static boolean isAssertionError(Class clazz) {
while (clazz != null) {
if (clazz.getName().equals("java.lang.AssertionError")) {
return true;
}
clazz = clazz.getSuperclass();
}
return false;
}

} // JUnitTestRunner

Loading…
Cancel
Save