diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 80171e788..5a4b73cba 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -248,6 +248,7 @@ Ludovic Claude
Maarten Coene
Magesh Umasankar
Maneesh Sahu
+Marc Guillemot
Marcel Schutte
Marcus Börger
Mario Frasca
diff --git a/WHATSNEW b/WHATSNEW
index 29dedcf60..0af7f1d2f 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -18,6 +18,10 @@ Fixed bugs:
It specified the SSH configuration file (typically ${user.home}/.ssh/config)
defining the username and keyfile to be used per host.
+ * "legacy-xml" formatter of junitlauncher task wasn't writing out
+ exceptions that happen in @BeforeAll method of a test. This is now fixed.
+ Bugzilla Report 63850
+
Other changes:
--------------
diff --git a/contributors.xml b/contributors.xml
index 61040c2bd..55941aa9d 100644
--- a/contributors.xml
+++ b/contributors.xml
@@ -1032,6 +1032,10 @@
Maneesh
Sahu
+
+ Marc
+ Guillemot
+
Marcel
Schutte
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
index 13e552cab..dad1cc83c 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
@@ -232,12 +232,20 @@ class LegacyXmlResultFormatter extends AbstractJUnitResultFormatter implements T
void writeTestCase(final XMLStreamWriter writer) throws XMLStreamException {
for (final Map.Entry entry : testIds.entrySet()) {
final TestIdentifier testId = entry.getKey();
- if (!testId.isTest()) {
- // only interested in test methods
+ if (!testId.isTest() && !failed.containsKey(testId)) {
+ // only interested in test methods unless there was a failure,
+ // in which case we want the exception reported
+ // (https://bz.apache.org/bugzilla/show_bug.cgi?id=63850)
continue;
}
- // find the parent class of this test method
- final Optional parentClassSource = findFirstParentClassSource(testId);
+ // find the associated class of this test
+ final Optional parentClassSource;
+ if (testId.isTest()) {
+ parentClassSource = findFirstParentClassSource(testId);
+ }
+ else {
+ parentClassSource = findFirstClassSource(testId);
+ }
if (!parentClassSource.isPresent()) {
continue;
}
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 1bb53c13d..56596c56a 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
@@ -24,6 +24,8 @@ import static org.example.junitlauncher.Tracker.verifySuccess;
import static org.example.junitlauncher.Tracker.wasTestRun;
import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -174,6 +176,18 @@ public class JUnitLauncherTaskTest {
Assert.assertTrue("JupiterSampleTest#testSkipped was expected to be skipped", verifySkipped(trackerFile,
JupiterSampleTest.class.getName(), "testSkipped"));
Assert.assertFalse("ForkedTest wasn't expected to be run", wasTestRun(trackerFile, ForkedTest.class.getName()));
+
+ verifyLegacyXMLFile("TEST-org.example.junitlauncher.jupiter.JupiterSampleTestFailingBeforeAll.xml", "");
+ verifyLegacyXMLFile("TEST-org.example.junitlauncher.jupiter.JupiterSampleTestFailingStatic.xml", "Caused by: java.lang.RuntimeException: Intentional exception from static init block");
+ }
+
+ private void verifyLegacyXMLFile(final String fileName, final String expectedContentExtract) throws IOException {
+ final String outputDir = buildRule.getProject().getProperty("output.dir");
+ final Path xmlFile = Paths.get(outputDir, fileName);
+
+ Assert.assertTrue("XML file doesn't exist: " + xmlFile, Files.exists(xmlFile));
+ final String content = new String(Files.readAllBytes(xmlFile), StandardCharsets.UTF_8);
+ Assert.assertTrue(fileName + " doesn't contain " + expectedContentExtract, content.contains(expectedContentExtract));
}
/**
diff --git a/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTestFailingStatic.java b/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTestFailingStatic.java
new file mode 100644
index 000000000..2c88d6693
--- /dev/null
+++ b/src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTestFailingStatic.java
@@ -0,0 +1,39 @@
+/*
+ * 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.Test;
+
+/**
+ *
+ */
+public class JupiterSampleTestFailingStatic {
+
+ static {
+ if (true) {
+ throw new RuntimeException("Intentional exception from static init block");
+ }
+ }
+
+
+ @Test
+ void testSucceeds() {
+ System.out.println("hello");
+ }
+
+}