Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.launcher.TestIdentifier;
import org.junit.platform.launcher.TestPlan;

class TestSuiteXmlRenderer {
Expand Down Expand Up @@ -73,8 +77,17 @@ public void toXml(XMLStreamWriter xml, TestData suite, Collection<TestData> test
xml.writeAttribute("package", "");
xml.writeEmptyElement("properties");

// JUnitParams generates report names based on parameter values rather than parameter types,
// which can result in duplicate test names in the XML output. This situation arises when
// two test methods have identical names but differ in parameter types; however, their
// string representations may be the same (e.g., Integer 1 and Long 1).
Set<String> reportedTests = new HashSet<>();
for (TestData testCase : tests) {
testRenderer.toXml(xml, testCase);
// apply duplicate check only for vintage test
if (!isVintageTest(testCase.getId())
|| reportedTests.add(testCase.getId().getLegacyReportingName())) {
testRenderer.toXml(xml, testCase);
}
}

writeTextElement(xml, "system-out", suite.getStdOut());
Expand All @@ -90,4 +103,12 @@ private String getHostname() {
return "localhost";
}
}

private boolean isVintageTest(TestIdentifier testIdentifier) {
return testIdentifier
.getParentIdObject()
.flatMap(UniqueId::getEngineId)
.filter("junit-vintage"::equals)
.isPresent();
}
}
Loading