This is an automated email from the ASF dual-hosted git repository.
jkf pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git
The following commit(s) were added to refs/heads/master by this push:
new 35d3b9a @BeforeAll failing should break build. Pr 63479
35d3b9a is described below
commit 35d3b9ab11a264912daefdb40837fd0a20b64c2e
Author: jkf <[email protected]>
AuthorDate: Sat Jun 1 13:48:30 2019 +0200
@BeforeAll failing should break build. Pr 63479
---
...r.jupiter.JupiterSampleTestFailingBeforeAll.txt | 0
.../testcases/taskdefs/optional/junitlauncher.xml | 18 +++++++
.../optional/junitlauncher/LauncherSupport.java | 2 +-
.../junitlauncher/JUnitLauncherTaskTest.java | 57 +++++++++++++++++-----
.../junit/org/example/junitlauncher/Tracker.java | 5 ++
.../jupiter/JupiterSampleTestFailingBeforeAll.java | 55 +++++++++++++++++++++
6 files changed, 125 insertions(+), 12 deletions(-)
diff --git
a/src/etc/testcases/taskdefs/optional/TEST-org.example.junitlauncher.jupiter.JupiterSampleTestFailingBeforeAll.txt
b/src/etc/testcases/taskdefs/optional/TEST-org.example.junitlauncher.jupiter.JupiterSampleTestFailingBeforeAll.txt
new file mode 100644
index 0000000..e69de29
diff --git a/src/etc/testcases/taskdefs/optional/junitlauncher.xml
b/src/etc/testcases/taskdefs/optional/junitlauncher.xml
index 1d6076e..cb9a541 100644
--- a/src/etc/testcases/taskdefs/optional/junitlauncher.xml
+++ b/src/etc/testcases/taskdefs/optional/junitlauncher.xml
@@ -300,6 +300,24 @@
</test>
</junitlauncher>
</target>
+
+ <target name="test-beforeall-failure-stops-build" depends="init">
+ <property name="junitlauncher.test.tracker.append.file"
value="${output.dir}/${test-beforeall-failure-stops-build.tracker}"/>
+ <junitlauncher>
+ <listener classname="org.example.junitlauncher.Tracker"
+ if="test-beforeall-failure-stops-build.tracker"/>
+ <test
name="org.example.junitlauncher.jupiter.JupiterSampleTestFailingBeforeAll"
haltOnFailure="true"/>
+ </junitlauncher>
+ </target>
+
+ <target name="test-beforeall-failure-continues-build" depends="init">
+ <property name="junitlauncher.test.tracker.append.file"
value="${output.dir}/${test-beforeall-failure-continues-build.tracker}"/>
+ <junitlauncher>
+ <listener classname="org.example.junitlauncher.Tracker"
+ if="test-beforeall-failure-continues-build.tracker"/>
+ <test
name="org.example.junitlauncher.jupiter.JupiterSampleTestFailingBeforeAll"/>
+ </junitlauncher>
+ </target>
<target name="test-method-with-tag-fileset" depends="init">
<property name="junitlauncher.test.tracker.append.file"
value="${output.dir}/${test-method-with-tag-fileset.tracker}"/>
diff --git
a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
index a052a26..65ba96e 100644
---
a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
+++
b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
@@ -304,7 +304,7 @@ public class LauncherSupport {
// print the summary to System.out
summary.printTo(new PrintWriter(System.out, true));
}
- final boolean hasTestFailures = summary.getTestsFailedCount() != 0;
+ final boolean hasTestFailures = summary.getTotalFailureCount() != 0;
if (hasTestFailures) {
// keep track of the test failure(s) for the entire launched
instance
this.testsFailed = true;
diff --git
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java
index 5bfd21e..1bb53c1 100644
---
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java
+++
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java
@@ -17,12 +17,24 @@
*/
package org.apache.tools.ant.taskdefs.optional.junitlauncher;
+import static org.example.junitlauncher.Tracker.verifyFailed;
+import static org.example.junitlauncher.Tracker.verifySetupFailed;
+import static org.example.junitlauncher.Tracker.verifySkipped;
+import static org.example.junitlauncher.Tracker.verifySuccess;
+import static org.example.junitlauncher.Tracker.wasTestRun;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project;
import
org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.JUnitLauncherTask;
import org.apache.tools.ant.util.LoaderUtils;
import org.example.junitlauncher.jupiter.JupiterSampleTest;
+import org.example.junitlauncher.jupiter.JupiterSampleTestFailingBeforeAll;
import org.example.junitlauncher.jupiter.JupiterTagSampleTest;
import org.example.junitlauncher.vintage.AlwaysFailingJUnit4Test;
import org.example.junitlauncher.vintage.ForkedTest;
@@ -32,16 +44,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import java.io.File;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-import static org.example.junitlauncher.Tracker.verifyFailed;
-import static org.example.junitlauncher.Tracker.verifySkipped;
-import static org.example.junitlauncher.Tracker.verifySuccess;
-import static org.example.junitlauncher.Tracker.wasTestRun;
-
/**
* Tests the {@link JUnitLauncherTask}
*/
@@ -78,7 +80,7 @@ public class JUnitLauncherTaskTest {
}
}
}
-
+
/**
* Tests that when a test, that's isn't configured with {@code
haltOnFailure=true}, continues the
* build even when there are test failures
@@ -368,6 +370,39 @@ public class JUnitLauncherTaskTest {
Assert.assertFalse("testMethodIncludeTagisNotExecutedTagSampleTest2
was expected NOT to be run", wasTestRun(tracker2,
JupiterTagSampleTest.class.getName(),
"testMethodIncludeTagisNotExecutedTagSampleTest2"));
}
+
+
+ /**
+ * Tests that failure at with beforeall stops the build
+ */
+ @Test
+ public void testBeforeAllFailureStopsBuild() throws Exception {
+ final String targetName = "test-beforeall-failure-stops-build";
+ final Path trackerFile = setupTrackerProperty(targetName);
+ try {
+ buildRule.executeTarget(targetName);
+ Assert.fail(targetName + " was expected to fail");
+ } catch (BuildException e) {
+ // expected, but do further tests to make sure the build failed
for expected reason
+ if (!verifySetupFailed(trackerFile,
JupiterSampleTestFailingBeforeAll.class.getName())) {
+ // throw back the original cause
+ throw e;
+ }
+ }
+ }
+
+ /**
+ * Tests that when a test, that's isn't configured with {@code
haltOnFailure=true}, continues the
+ * build even when there are test failures
+ */
+ @Test
+ public void testBeforeAllFailureContinuesBuild() throws Exception {
+ final String targetName = "test-beforeall-failure-continues-build";
+ final Path trackerFile = setupTrackerProperty(targetName);
+ buildRule.executeTarget(targetName);
+ Assert.assertTrue("Expected @BeforeAll failure to lead to failing
testcase", verifySetupFailed(trackerFile,
JupiterSampleTestFailingBeforeAll.class.getName()));
+ }
+
/**
* Tests execution of a test which is configured to execute only methods
with special tags, two classes specified
diff --git a/src/tests/junit/org/example/junitlauncher/Tracker.java
b/src/tests/junit/org/example/junitlauncher/Tracker.java
index 1437cd6..ba31ec8 100644
--- a/src/tests/junit/org/example/junitlauncher/Tracker.java
+++ b/src/tests/junit/org/example/junitlauncher/Tracker.java
@@ -143,6 +143,11 @@ public class Tracker implements TestResultFormatter {
final List<String> lines = readTrackerFile(trackerFile);
return lines.contains(TestExecutionResult.Status.FAILED +
":test-method:" + className + "#" + methodName);
}
+
+ public static boolean verifySetupFailed(final Path trackerFile, final
String className) throws IOException {
+ final List<String> lines = readTrackerFile(trackerFile);
+ return lines.contains(TestExecutionResult.Status.FAILED +
":test-class:" + className);
+ }
public static boolean verifySuccess(final Path trackerFile, final String
className, final String methodName) throws IOException {
final List<String> lines = readTrackerFile(trackerFile);
diff --git
a/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTestFailingBeforeAll.java
b/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTestFailingBeforeAll.java
new file mode 100644
index 0000000..d42e703
--- /dev/null
+++
b/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTestFailingBeforeAll.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.example.junitlauncher.jupiter;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ *
+ */
+public class JupiterSampleTestFailingBeforeAll {
+
+ private static final String message = "The quick brown fox jumps over the
lazy dog";
+
+ @BeforeAll
+ static void beforeAll() {
+ throw new RuntimeException("Intentional failure");
+ }
+
+ @BeforeEach
+ void beforeEach() {
+ }
+
+ @Test
+ void testSucceeds() {
+ System.out.println(message);
+ System.out.print("<some-other-message>Hello world! <!-- some comment
--></some-other-message>");
+ }
+
+ @AfterEach
+ void afterEach() {
+ }
+
+ @AfterAll
+ static void afterAll() {
+ }
+}