Browse Source

Merge from master

master
Maarten Coene 7 years ago
parent
commit
6745574ec8
3 changed files with 68 additions and 2 deletions
  1. +9
    -0
      WHATSNEW
  2. +3
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
  3. +56
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java

+ 9
- 0
WHATSNEW View File

@@ -1,6 +1,15 @@
Changes from Ant 1.9.11 TO Ant 1.9.12 Changes from Ant 1.9.11 TO Ant 1.9.12
===================================== =====================================


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.9.10 TO Ant 1.9.11 Changes from Ant 1.9.10 TO Ant 1.9.11
===================================== =====================================




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

@@ -383,9 +383,10 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
try { try {
Class testClass = null; Class testClass = null;
if (loader == null) { if (loader == null) {
testClass = Class.forName(junitTest.getName());
testClass = Class.forName(junitTest.getName(), false,
getClass().getClassLoader());
} else { } else {
testClass = Class.forName(junitTest.getName(), true,
testClass = Class.forName(junitTest.getName(), false,
loader); loader);
} }




+ 56
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java View File

@@ -25,6 +25,7 @@ import java.io.OutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;


import javafx.scene.control.Control;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
@@ -99,6 +100,35 @@ public class JUnitTestRunnerTest {
//assertEquals(runner.getFormatter().getError(), JUnitTestRunner.FAILURES, runner.getRetCode()); //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 // check that an exception in the constructor is noticed
@Test @Test
public void testInvalidTestCase() { public void testInvalidTestCase() {
@@ -134,6 +164,12 @@ public class JUnitTestRunnerTest {
true, true, true); 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) { protected TestRunner createRunnerForTestMethod(Class<?> clazz, String method) {
return new TestRunner(new JUnitTest(clazz.getName()), new String[] {method}, return new TestRunner(new JUnitTest(clazz.getName()), new String[] {method},
true, true, true); true, true, true);
@@ -196,6 +232,15 @@ public class JUnitTestRunnerTest {
public static class NoTestCase { 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 static class InvalidMethodTestCase extends TestCase {
public InvalidMethodTestCase(String name) { public InvalidMethodTestCase(String name) {
super(name); super(name);
@@ -251,6 +296,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 { public static class AssertionErrorTest {
@Test @Test
public void throwsAssertionError() { public void throwsAssertionError() {


Loading…
Cancel
Save