Browse Source

bz-63850 junitlaucher legacy-xml: don't lose exception from @BeforeAll

master
Marc Guillemot Jaikiran Pai 5 years ago
parent
commit
fc82dd1bf6
6 changed files with 74 additions and 4 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +4
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +12
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
  5. +14
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java
  6. +39
    -0
      src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTestFailingStatic.java

+ 1
- 0
CONTRIBUTORS View File

@@ -248,6 +248,7 @@ Ludovic Claude
Maarten Coene
Magesh Umasankar
Maneesh Sahu
Marc Guillemot
Marcel Schutte
Marcus Börger
Mario Frasca


+ 4
- 0
WHATSNEW View File

@@ -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:
--------------



+ 4
- 0
contributors.xml View File

@@ -1032,6 +1032,10 @@
<first>Maneesh</first>
<last>Sahu</last>
</name>
<name>
<first>Marc</first>
<last>Guillemot</last>
</name>
<name>
<first>Marcel</first>
<last>Schutte</last>


+ 12
- 4
src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java View File

@@ -232,12 +232,20 @@ class LegacyXmlResultFormatter extends AbstractJUnitResultFormatter implements T
void writeTestCase(final XMLStreamWriter writer) throws XMLStreamException {
for (final Map.Entry<TestIdentifier, Stats> 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<ClassSource> parentClassSource = findFirstParentClassSource(testId);
// find the associated class of this test
final Optional<ClassSource> parentClassSource;
if (testId.isTest()) {
parentClassSource = findFirstParentClassSource(testId);
}
else {
parentClassSource = findFirstClassSource(testId);
}
if (!parentClassSource.isPresent()) {
continue;
}


+ 14
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTaskTest.java View File

@@ -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", "<failure message=\"Intentional failure\" type=\"java.lang.RuntimeException\">");
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));
}

/**


+ 39
- 0
src/tests/junit/org/example/junitlauncher/jupiter/JupiterSampleTestFailingStatic.java View File

@@ -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");
}

}

Loading…
Cancel
Save