You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by ma...@apache.org on 2018/04/04 11:24:45 UTC
ant git commit: Delay the class initialization of the test classes
untill they are passed to JUnit.
Repository: ant
Updated Branches:
refs/heads/master aa01cc4bd -> 30c9dee9b
Delay the class initialization of the test classes untill they are passed to JUnit.
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/30c9dee9
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/30c9dee9
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/30c9dee9
Branch: refs/heads/master
Commit: 30c9dee9bad90e56703554d21819cec6033276dc
Parents: aa01cc4
Author: Maarten Coene <ma...@apache.org>
Authored: Wed Apr 4 13:23:40 2018 +0200
Committer: Maarten Coene <ma...@apache.org>
Committed: Wed Apr 4 13:23:40 2018 +0200
----------------------------------------------------------------------
WHATSNEW | 9 ++++
.../optional/junit/JUnitTestRunner.java | 5 +-
.../optional/junit/JUnitTestRunnerTest.java | 56 ++++++++++++++++++++
3 files changed, 68 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/30c9dee9/WHATSNEW
----------------------------------------------------------------------
diff --git a/WHATSNEW b/WHATSNEW
index 936cb30..dff8f7c 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -1,6 +1,15 @@
Changes from Ant 1.10.3 TO Ant 1.10.4
=====================================
+Fixed bugs:
+-----------
+
+ * Delay the class initialization of the test classes untill they are
+ passed to JUnit. This way we can avoid that failing static initializers
+ from non-test classes are reported as error when the 'skipNonTests' option
+ is 'true'.
+ Bugzilla Report 60062
+
Changes from Ant 1.10.2 TO Ant 1.10.3
=====================================
http://git-wip-us.apache.org/repos/asf/ant/blob/30c9dee9/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
index 84e595a..393211b 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
@@ -383,9 +383,10 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
try {
Class<?> testClass;
if (loader == null) {
- testClass = Class.forName(junitTest.getName());
+ testClass = Class.forName(junitTest.getName(), false,
+ getClass().getClassLoader());
} else {
- testClass = Class.forName(junitTest.getName(), true,
+ testClass = Class.forName(junitTest.getName(), false,
loader);
}
http://git-wip-us.apache.org/repos/asf/ant/blob/30c9dee9/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
index 292eb60..92d63a9 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
@@ -21,6 +21,7 @@ import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
+import javafx.scene.control.Control;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -100,6 +101,35 @@ public class JUnitTestRunnerTest {
//assertEquals(runner.getFormatter().getError(), JUnitTestRunner.FAILURES, runner.getRetCode());
}
+ // check that something which is not a testcase doesn't generate an error
+ // when skipping non-test classes
+ @Test
+ public void testSkipNonTestsNoTestCase() {
+ TestRunner runner = createRunner(NoTestCase.class, true);
+ runner.run();
+ assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode());
+ }
+
+ // check that something which is not a testcase with a failing static init doesn't generate an error
+ // when skipping non-test classes
+ @Test
+ public void testSkipNonTestsNoTestCaseFailingStaticInit() {
+ TestRunner runner = createRunner(NoTestCaseStaticInitializerError.class, true);
+ runner.run();
+ assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode());
+ }
+
+ @Test
+ public void testStaticInitializerErrorTestCase() {
+ TestRunner runner = createRunner(StaticInitializerErrorTestCase.class);
+ runner.run();
+ // On junit3 this is a FAILURE, on junit4 this is an ERROR
+ int ret = runner.getRetCode();
+ if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) {
+ fail("Unexpected result " + ret + " from junit runner");
+ }
+ }
+
// check that an exception in the constructor is noticed
@Test
public void testInvalidTestCase() {
@@ -135,6 +165,12 @@ public class JUnitTestRunnerTest {
true, true, true);
}
+ protected TestRunner createRunner(Class<?> clazz, boolean skipNonTests) {
+ JUnitTest test = new JUnitTest(clazz.getName());
+ test.setSkipNonTests(skipNonTests);
+ return new TestRunner(test, null, true, true, true);
+ }
+
protected TestRunner createRunnerForTestMethod(Class<?> clazz, String method) {
return new TestRunner(new JUnitTest(clazz.getName()), new String[] {method},
true, true, true);
@@ -197,6 +233,15 @@ public class JUnitTestRunnerTest {
public static class NoTestCase {
}
+ public static class NoTestCaseStaticInitializerError {
+ static {
+ error();
+ }
+ private static void error() {
+ throw new NullPointerException("thrown on purpose");
+ }
+ }
+
public static class InvalidMethodTestCase extends TestCase {
public InvalidMethodTestCase(String name) {
super(name);
@@ -252,6 +297,17 @@ public class JUnitTestRunnerTest {
}
}
+ public static class StaticInitializerErrorTestCase extends TestCase {
+ static {
+ error();
+ }
+ private static void error() {
+ throw new NullPointerException("thrown on purpose");
+ }
+ public void testA() {
+ }
+ }
+
public static class AssertionErrorTest {
@Test
public void throwsAssertionError() {