From a3c533d260c06eca7404eeb71e4c0edcfc6e47d9 Mon Sep 17 00:00:00 2001 From: Anshuman Mishra Date: Wed, 26 Mar 2025 18:23:50 -0700 Subject: [PATCH 1/3] Handle duplicate test names in report --- .../junit5/TestSuiteXmlRenderer.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestSuiteXmlRenderer.java b/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestSuiteXmlRenderer.java index cd1d5276..fd3f21e5 100644 --- a/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestSuiteXmlRenderer.java +++ b/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestSuiteXmlRenderer.java @@ -10,7 +10,9 @@ 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.launcher.TestPlan; @@ -73,8 +75,15 @@ public void toXml(XMLStreamWriter xml, TestData suite, Collection 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 reportedTests = new HashSet<>(); for (TestData testCase : tests) { - testRenderer.toXml(xml, testCase); + if (reportedTests.add(testCase.getId().getLegacyReportingName())) { + testRenderer.toXml(xml, testCase); + } } writeTextElement(xml, "system-out", suite.getStdOut()); From 876052761b7936c580017ac6aacdc22665cb47f8 Mon Sep 17 00:00:00 2001 From: Anshuman Mishra Date: Wed, 24 Sep 2025 14:12:43 -0700 Subject: [PATCH 2/3] update duplicate check to only apply for vintage test --- .../junit5/TestSuiteXmlRenderer.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestSuiteXmlRenderer.java b/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestSuiteXmlRenderer.java index fd3f21e5..c49f43f5 100644 --- a/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestSuiteXmlRenderer.java +++ b/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestSuiteXmlRenderer.java @@ -15,6 +15,9 @@ 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 { @@ -81,7 +84,8 @@ public void toXml(XMLStreamWriter xml, TestData suite, Collection test // string representations may be the same (e.g., Integer 1 and Long 1). Set reportedTests = new HashSet<>(); for (TestData testCase : tests) { - if (reportedTests.add(testCase.getId().getLegacyReportingName())) { + // apply duplicate check only for vintage test + if (!isVintageTest(testCase.getId()) || reportedTests.add(testCase.getId().getLegacyReportingName())) { testRenderer.toXml(xml, testCase); } } @@ -99,4 +103,12 @@ private String getHostname() { return "localhost"; } } + + private boolean isVintageTest(TestIdentifier testIdentifier) { + return testIdentifier + .getParentIdObject() + .flatMap(UniqueId::getEngineId) + .filter("junit-vintage"::equals) + .isPresent(); + } } From cee84499a24c918e2f14bc6daa1733f9a8827e8b Mon Sep 17 00:00:00 2001 From: Anshuman Mishra Date: Wed, 24 Sep 2025 14:25:21 -0700 Subject: [PATCH 3/3] run formatter --- .../junit5/TestSuiteXmlRenderer.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestSuiteXmlRenderer.java b/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestSuiteXmlRenderer.java index c49f43f5..e6b16ec0 100644 --- a/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestSuiteXmlRenderer.java +++ b/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestSuiteXmlRenderer.java @@ -15,7 +15,6 @@ 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; @@ -85,7 +84,8 @@ public void toXml(XMLStreamWriter xml, TestData suite, Collection test Set reportedTests = new HashSet<>(); for (TestData testCase : tests) { // apply duplicate check only for vintage test - if (!isVintageTest(testCase.getId()) || reportedTests.add(testCase.getId().getLegacyReportingName())) { + if (!isVintageTest(testCase.getId()) + || reportedTests.add(testCase.getId().getLegacyReportingName())) { testRenderer.toXml(xml, testCase); } } @@ -106,9 +106,9 @@ private String getHostname() { private boolean isVintageTest(TestIdentifier testIdentifier) { return testIdentifier - .getParentIdObject() - .flatMap(UniqueId::getEngineId) - .filter("junit-vintage"::equals) - .isPresent(); + .getParentIdObject() + .flatMap(UniqueId::getEngineId) + .filter("junit-vintage"::equals) + .isPresent(); } }