Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions documentation/modules/ROOT/pages/release-notes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Please refer to the xref:overview.adoc[User Guide] for comprehensive
reference documentation for programmers writing tests, extension authors, and engine
authors as well as build tool and IDE vendors.

include::partial$release-notes/release-notes-5.14.4.adoc[]

include::partial$release-notes/release-notes-5.14.3.adoc[]

include::partial$release-notes/release-notes-5.14.2.adoc[]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[[v5.14.4]]
== 5.14.4

*Date of Release:* ❓

*Scope:* Bug fix for legacy XML reporting of `@ClassTemplate`/`@ParameterizedClass` tests

For a complete list of all _closed_ issues and pull requests for this release, consult the
link:{junit-framework-repo}+/milestone/MILESTONE_NUMBER?closed=1+[5.14.4] milestone page in the JUnit
repository on GitHub.


[[v5.14.4-junit-platform]]
=== JUnit Platform

No changes.


[[v5.14.4-junit-jupiter]]
=== JUnit Jupiter

[[v5.14.4-junit-jupiter-bug-fixes]]
==== Bug Fixes

* Include index of `@ClassTemplate`/`@ParameterizedClass` invocations in test names in
legacy XML reports to make them unique.
* Legacy XML reports now include parent display names to make it easier to distinguish
between invocations for different parameters.


[[v5.14.4-junit-vintage]]
=== JUnit Vintage

No changes.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public final Type getType() {
}

@Override
public final String getLegacyReportingName() {
protected final String getLegacyReportingBaseName() {
return getTestClass().getName();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.junit.jupiter.engine.support.JupiterThrowableCollectorFactory.createThrowableCollector;

import java.util.List;
import java.util.OptionalInt;
import java.util.Set;
import java.util.function.Function;
import java.util.function.UnaryOperator;
Expand Down Expand Up @@ -80,8 +81,13 @@ public Type getType() {
}

@Override
public String getLegacyReportingName() {
return getTestClass().getName() + "[" + index + "]";
protected String getLegacyReportingBaseName() {
return getTestClass().getName();
}

@Override
protected OptionalInt getLegacyReportingIndex() {
return OptionalInt.of(index);
}

// --- TestClassAware ------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

package org.junit.jupiter.engine.descriptor;

import java.util.OptionalInt;

import org.junit.jupiter.api.DynamicNode;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.engine.config.JupiterConfiguration;
Expand All @@ -34,15 +36,24 @@ abstract class DynamicNodeTestDescriptor extends JupiterTestDescriptor {
}

@Override
public String getLegacyReportingName() {
protected final String getLegacyReportingBaseName() {
// @formatter:off
return getParent()
.map(TestDescriptor::getLegacyReportingName)
.orElseGet(this::getDisplayName)
+ "[" + index + "]";
.map(parent -> {
if (parent instanceof JupiterTestDescriptor) {
return ((JupiterTestDescriptor) parent).getLegacyReportingBaseName();
}
return parent.getLegacyReportingName();
})
.orElseGet(this::getDisplayName);
// @formatter:on
}

@Override
protected OptionalInt getLegacyReportingIndex() {
return OptionalInt.of(index);
}

@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) {
ExtensionContext extensionContext = new DynamicExtensionContext(context.getExtensionContext(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import static java.util.Collections.emptySet;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toCollection;
import static java.util.stream.Collectors.toSet;
import static org.apiguardian.api.API.Status.INTERNAL;
Expand All @@ -24,11 +25,13 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import java.util.stream.IntStream;

import org.apiguardian.api.API;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -77,6 +80,35 @@ public abstract class JupiterTestDescriptor extends AbstractTestDescriptor

// --- TestDescriptor ------------------------------------------------------

@Override
public final String getLegacyReportingName() {
return getLegacyReportingBaseName()
+ getLegacyReportingIndexes().mapToObj(i -> "[" + i + "]").collect(joining());
}

protected String getLegacyReportingBaseName() {
return getDisplayName();
}

private IntStream getLegacyReportingIndexes() {
OptionalInt ownIndex = getLegacyReportingIndex();
return getParent() //
.map(it -> it instanceof JupiterTestDescriptor //
? ((JupiterTestDescriptor) it).getLegacyReportingIndexes() //
: null) //
.map(parentIndexes -> IntStream.concat(parentIndexes, asStream(ownIndex))) //
.orElse(asStream(ownIndex));
}

private IntStream asStream(final OptionalInt optInt) {
return optInt.isPresent() ? IntStream.of(optInt.getAsInt()) : IntStream.empty();

}

protected OptionalInt getLegacyReportingIndex() {
return OptionalInt.empty();
}

static Set<TestTag> getTags(AnnotatedElement element, Supplier<String> elementDescription,
Supplier<TestSource> sourceProvider, Consumer<DiscoveryIssue> issueCollector) {
AtomicReference<TestSource> source = new AtomicReference<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public final Set<TestTag> getTags() {
}

@Override
public String getLegacyReportingName() {
protected final String getLegacyReportingBaseName() {
return String.format("%s(%s)", getTestMethod().getName(),
ClassUtils.nullSafeToString(Class::getSimpleName, getTestMethod().getParameterTypes()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.apiguardian.api.API.Status.INTERNAL;

import java.lang.reflect.Method;
import java.util.OptionalInt;
import java.util.Set;
import java.util.function.UnaryOperator;

Expand Down Expand Up @@ -70,8 +71,8 @@ public Set<ExclusiveResource> getExclusiveResources() {
}

@Override
public String getLegacyReportingName() {
return super.getLegacyReportingName() + "[" + index + "]";
protected OptionalInt getLegacyReportingIndex() {
return OptionalInt.of(index);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.net.UnknownHostException;
import java.text.NumberFormat;
import java.time.LocalDateTime;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
Expand Down Expand Up @@ -116,7 +117,7 @@ private void writeXmlReport(TestIdentifier testIdentifier, Map<TestIdentifier, A
Writer out) throws XMLStreamException {

try (XmlReport report = new XmlReport(out)) {
report.write(testIdentifier, tests);
report.write(testIdentifier, tests, this.reportData.getTestPlan());
}
}

Expand All @@ -131,16 +132,16 @@ private class XmlReport implements AutoCloseable {
this.xml = factory.createXMLStreamWriter(this.out);
}

void write(TestIdentifier testIdentifier, Map<TestIdentifier, AggregatedTestResult> tests)
void write(TestIdentifier testIdentifier, Map<TestIdentifier, AggregatedTestResult> tests, TestPlan testPlan)
throws XMLStreamException {
xml.writeStartDocument("UTF-8", "1.0");
newLine();
writeTestsuite(testIdentifier, tests);
writeTestsuite(testIdentifier, tests, testPlan);
xml.writeEndDocument();
}

private void writeTestsuite(TestIdentifier testIdentifier, Map<TestIdentifier, AggregatedTestResult> tests)
throws XMLStreamException {
private void writeTestsuite(TestIdentifier testIdentifier, Map<TestIdentifier, AggregatedTestResult> tests,
TestPlan testPlan) throws XMLStreamException {

// NumberFormat is not thread-safe. Thus, we instantiate it here and pass it to
// writeTestcase instead of using a constant
Expand All @@ -154,10 +155,10 @@ private void writeTestsuite(TestIdentifier testIdentifier, Map<TestIdentifier, A
writeSystemProperties();

for (Entry<TestIdentifier, AggregatedTestResult> entry : tests.entrySet()) {
writeTestcase(entry.getKey(), entry.getValue(), numberFormat);
writeTestcase(entry.getKey(), entry.getValue(), numberFormat, testPlan);
}

writeOutputElement("system-out", formatNonStandardAttributesAsString(testIdentifier));
writeOutputElement("system-out", formatNonStandardAttributesAsString(testIdentifier, testPlan));

xml.writeEndElement();
newLine();
Expand Down Expand Up @@ -198,7 +199,7 @@ private void writeSystemProperties() throws XMLStreamException {
}

private void writeTestcase(TestIdentifier testIdentifier, AggregatedTestResult testResult,
NumberFormat numberFormat) throws XMLStreamException {
NumberFormat numberFormat, TestPlan testPlan) throws XMLStreamException {

xml.writeStartElement("testcase");

Expand All @@ -211,7 +212,7 @@ private void writeTestcase(TestIdentifier testIdentifier, AggregatedTestResult t

List<String> systemOutElements = new ArrayList<>();
List<String> systemErrElements = new ArrayList<>();
systemOutElements.add(formatNonStandardAttributesAsString(testIdentifier));
systemOutElements.add(formatNonStandardAttributesAsString(testIdentifier, testPlan));
collectReportEntries(testIdentifier, systemOutElements, systemErrElements);
writeOutputElements("system-out", systemOutElements);
writeOutputElements("system-err", systemErrElements);
Expand Down Expand Up @@ -334,9 +335,16 @@ private LocalDateTime getCurrentDateTime() {
return LocalDateTime.now(reportData.getClock()).withNano(0);
}

private String formatNonStandardAttributesAsString(TestIdentifier testIdentifier) {
private String formatNonStandardAttributesAsString(TestIdentifier testIdentifier, TestPlan testPlan) {
ArrayDeque<String> displayNames = new ArrayDeque<>();
TestIdentifier current = testIdentifier;
while (current != null) {
displayNames.push(current.getDisplayName());
current = testPlan.getParent(current).orElse(null);
}
String fullDisplayName = String.join(" > ", displayNames);
return "unique-id: " + testIdentifier.getUniqueId() //
+ "\ndisplay-name: " + testIdentifier.getDisplayName();
+ "\ndisplay-name: " + fullDisplayName;
}

private void writeOutputElements(String elementName, List<String> elements) throws XMLStreamException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.junit.platform.testkit.engine.EventConditions.event;
import static org.junit.platform.testkit.engine.EventConditions.finishedSuccessfully;
import static org.junit.platform.testkit.engine.EventConditions.finishedWithFailure;
import static org.junit.platform.testkit.engine.EventConditions.legacyReportingName;
import static org.junit.platform.testkit.engine.EventConditions.started;
import static org.junit.platform.testkit.engine.EventConditions.test;
import static org.junit.platform.testkit.engine.EventConditions.uniqueId;
Expand Down Expand Up @@ -106,6 +107,7 @@
import org.junit.platform.engine.reporting.ReportEntry;
import org.junit.platform.testkit.engine.EngineExecutionResults;
import org.junit.platform.testkit.engine.Event;
import org.junit.platform.testkit.engine.EventType;
import org.junit.platform.testkit.engine.Events;

@SuppressWarnings("JUnitMalformedDeclaration")
Expand All @@ -132,19 +134,19 @@ void injectsParametersIntoClass(Class<?> classTemplateClass) {
event(container("#1"), started()), //
event(dynamicTestRegistered("test1")), //
event(dynamicTestRegistered("test2")), //
event(test("test1"), started()), //
event(test("test1"), legacyReportingName("test1()[1]"), started()), //
event(test("test1"), finishedSuccessfully()), //
event(test("test2"), started()), //
event(test("test2"), legacyReportingName("test2()[1]"), started()), //
event(test("test2"), finishedSuccessfully()), //
event(container("#1"), finishedSuccessfully()), //

event(dynamicTestRegistered("#2"), displayName("[2] %s1".formatted(parameterNamePrefix))), //
event(container("#2"), started()), //
event(dynamicTestRegistered("test1")), //
event(dynamicTestRegistered("test2")), //
event(test("test1"), started()), //
event(test("test1"), legacyReportingName("test1()[2]"), started()), //
event(test("test1"), finishedWithFailure(message(it -> it.contains("negative")))), //
event(test("test2"), started()), //
event(test("test2"), legacyReportingName("test2()[2]"), started()), //
event(test("test2"), finishedWithFailure(message(it -> it.contains("negative")))), //
event(container("#2"), finishedSuccessfully()), //

Expand Down Expand Up @@ -461,6 +463,18 @@ void supportsNestedParameterizedClass(Class<?> classTemplateClass) {
"afterAll: %s".formatted(classTemplateClass.getSimpleName())
// @formatter:on
);
var legacyReportingNames = results.testEvents() //
.filter(it -> it.getType() == EventType.STARTED) //
.map(e -> e.getTestDescriptor().getLegacyReportingName());
assertThat(legacyReportingNames).containsExactly( //
"test(boolean, TestReporter)[1][1][1]", //
"test(boolean, TestReporter)[1][1][2]", //
"test(boolean, TestReporter)[1][2][1]", //
"test(boolean, TestReporter)[1][2][2]", //
"test(boolean, TestReporter)[2][1][1]", //
"test(boolean, TestReporter)[2][1][2]", //
"test(boolean, TestReporter)[2][2][1]", //
"test(boolean, TestReporter)[2][2][2]");
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void writesFileForSingleSucceedingTest() throws Exception {
assertThat(testcase.attr("classname")).isEqualTo("dummy");
assertThat(testcase.child("system-out").text()) //
.containsSubsequence("unique-id: [engine:dummy]/[test:succeedingTest]",
"display-name: display<-->Name 😎");
"display-name: dummy > display<-->Name 😎");

assertThat(testsuite.find("skipped")).isEmpty();
assertThat(testsuite.find("failure")).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,14 @@ void writesReportEntry() throws Exception {

@Test
void writesCapturedOutput() throws Exception {
var uniqueId = engineDescriptor.getUniqueId().append("test", "test");
var testDescriptor = new TestDescriptorStub(uniqueId, "successfulTest");
engineDescriptor.addChild(testDescriptor);
var classDescriptor = new TestDescriptorStub(engineDescriptor.getUniqueId().append("class", "SomeClass"),
"SomeClass");
engineDescriptor.addChild(classDescriptor);

var testDescriptor = new TestDescriptorStub(classDescriptor.getUniqueId().append("test", "successfulTest"),
"successfulTest");
classDescriptor.addChild(testDescriptor);

var testPlan = TestPlan.from(true, Set.of(engineDescriptor), configParams, dummyOutputDirectoryCreator());

var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
Expand All @@ -103,13 +108,14 @@ void writesCapturedOutput() throws Exception {
"foo", "bar"));
reportData.addReportEntry(TestIdentifier.from(testDescriptor), reportEntry);
reportData.addReportEntry(TestIdentifier.from(testDescriptor), ReportEntry.from(Map.of("baz", "qux")));
reportData.markFinished(testPlan.getTestIdentifier(uniqueId), successful());
reportData.markFinished(testPlan.getTestIdentifier(testDescriptor.getUniqueId()), successful());

var testsuite = writeXmlReport(testPlan, reportData);

assertValidAccordingToJenkinsSchema(testsuite.document());
assertThat(testsuite.find("system-out").text(0)) //
.containsSubsequence("unique-id: ", "test:test", "display-name: successfulTest");
.containsSubsequence("unique-id: [engine:engine]/[class:SomeClass]/[test:successfulTest]",
"display-name: Engine > SomeClass > successfulTest");
assertThat(testsuite.find("system-out").text(1)) //
.containsSubsequence("Report Entry #1 (timestamp: ", "- foo: bar", "Report Entry #2 (timestamp: ",
"- baz: qux");
Expand Down
Loading
Loading