You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "AzazelSensei (via GitHub)" <gi...@apache.org> on 2026/08/13 10:38:36 UTC
[PR] Fix #3303: distinguish JUnit 6 ParameterizedClass invocations [maven-surefire]
AzazelSensei opened a new pull request, #3432:
URL: https://github.com/apache/maven-surefire/pull/3432
Following this checklist to help us incorporate your contribution quickly and easily:
- [x] Each commit in the pull request should have a meaningful subject line and body.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Run `mvn clean install` to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
- [ ] You have run the integration tests successfully (`mvn -Prun-its clean install`).
Targeted module tests: `mvn -pl surefire-providers/surefire-junit-platform test -Dtest=RunListenerAdapterTest,JUnitPlatformProviderTest` (75 passed). Did not run the full ITS profile locally.
Fixes #3303.
`rerunFailingTestsCount` treats two reports with the same class+method name as one test. JUnit 5 `@ParameterizedTest` already puts `[N]` on the method legacy name. JUnit 6 `@ParameterizedClass` does not: the index lives on a `[class-template-invocation:#N]` parent with a `ClassSource`, so `hasParameterizedParent` misses it and both invocations look like `testSomething()`. A fail then a pass on the next index gets collapsed into a flake/pass.
This reads that unique-id segment and appends `[N]` when the method name does not already have it.
- [x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix #3303: distinguish JUnit 6 ParameterizedClass invocations [maven-surefire]
Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy commented on PR #3432:
URL: https://github.com/apache/maven-surefire/pull/3432#issuecomment-5404144858
@AzazelSensei, thanks for your contribution!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix #3303: distinguish JUnit 6 ParameterizedClass invocations [maven-surefire]
Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy commented on code in PR #3432:
URL: https://github.com/apache/maven-surefire/pull/3432#discussion_r3795144353
##########
surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java:
##########
@@ -462,14 +498,26 @@ private ResultDisplay toClassMethodName(TestIdentifier testIdentifier) {
.map(TestIdentifier::getLegacyReportingName)
.anyMatch(legacyReportingName -> legacyReportingName.matches("^\\[.+]$"));
boolean isTestTemplate = testIdentifier.getLegacyReportingName().matches("^.*\\[\\d+]$");
-
- boolean parameterized = isParameterized || hasParameterizedParent || isTestTemplate;
+ // JUnit 6 @ParameterizedClass parents have a ClassSource, so they are missed by
+ // hasParameterizedParent, and the method legacy name no longer includes [N] (#3303).
+ String classTemplateInvocationSuffix = extractClassTemplateInvocationSuffix(testIdentifier.getUniqueId());
+
+ boolean parameterized = isParameterized
+ || hasParameterizedParent
+ || isTestTemplate
+ || !classTemplateInvocationSuffix.isEmpty();
String methodName = methodSource.getMethodName();
String description = testIdentifier.getLegacyReportingName();
boolean equalDescriptions = methodDisplay.equals(description);
boolean hasLegacyDescription = description.startsWith(methodName + '(');
boolean hasDisplayName = !equalDescriptions || !hasLegacyDescription;
String methodDesc = parameterized ? description : methodName;
+ // JUnit 6.1+ already puts the class index before a method invocation index
Review Comment:
I think the class-invocation index is appended after the method index (foo()[m][c]), or collapses on the diagonal (c==m → foo()[c]). This contradicts the [class][method].
2 class invocations × method invocations #1/#2 → foo(String)[1], foo(String)[2][1], foo(String)[1][2], foo(String)[2]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix #3303: distinguish JUnit 6 ParameterizedClass invocations [maven-surefire]
Posted by "AzazelSensei (via GitHub)" <gi...@apache.org>.
AzazelSensei commented on PR #3432:
URL: https://github.com/apache/maven-surefire/pull/3432#issuecomment-5391835672
Rebased onto master and addressed both notes: UniqueId.parse().getSegments(), and the reported name is [class][method] now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix #3303: distinguish JUnit 6 ParameterizedClass invocations [maven-surefire]
Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy commented on code in PR #3432:
URL: https://github.com/apache/maven-surefire/pull/3432#discussion_r3795127328
##########
surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java:
##########
@@ -208,6 +208,42 @@ private Stream<TestIdentifier> collectAllTestIdentifiersInHierarchy(TestIdentifi
.orElseGet(Stream::empty);
}
+ /**
+ * Build a {@code [outer][inner]} suffix from every JUnit Jupiter
+ * {@code [class-template-invocation:#N]} unique-id segment. Nested
+ * {@code @ParameterizedClass} declarations emit more than one; taking only
+ * the last would collapse outer #1/inner #1 with outer #2/inner #1.
+ *
+ * @param uniqueId the platform unique id string
+ * @return the suffix, or an empty string when the id has no class-template invocation
+ */
+ private static String extractClassTemplateInvocationSuffix(String uniqueId) {
+ if (uniqueId == null) {
+ return "";
+ }
+ String marker = "[class-template-invocation:";
Review Comment:
Is there anything available to extract segments from a uniqueId representation rather than parsing manually?
Maybe?
```
UniqueId.parse(uniqueId).getSegments()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix #3303: distinguish JUnit 6 ParameterizedClass invocations [maven-surefire]
Posted by "AzazelSensei (via GitHub)" <gi...@apache.org>.
AzazelSensei commented on PR #3432:
URL: https://github.com/apache/maven-surefire/pull/3432#issuecomment-5291495987
Nested class-template indices are all kept now, so outer #1/inner #1 and outer #2/inner #1 no longer collapse. Also stopped appending again when the legacy name already has the class index.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix #3303: distinguish JUnit 6 ParameterizedClass invocations [maven-surefire]
Posted by "AzazelSensei (via GitHub)" <gi...@apache.org>.
AzazelSensei commented on code in PR #3432:
URL: https://github.com/apache/maven-surefire/pull/3432#discussion_r3841309628
##########
surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java:
##########
@@ -208,6 +208,42 @@ private Stream<TestIdentifier> collectAllTestIdentifiersInHierarchy(TestIdentifi
.orElseGet(Stream::empty);
}
+ /**
+ * Build a {@code [outer][inner]} suffix from every JUnit Jupiter
+ * {@code [class-template-invocation:#N]} unique-id segment. Nested
+ * {@code @ParameterizedClass} declarations emit more than one; taking only
+ * the last would collapse outer #1/inner #1 with outer #2/inner #1.
+ *
+ * @param uniqueId the platform unique id string
+ * @return the suffix, or an empty string when the id has no class-template invocation
+ */
+ private static String extractClassTemplateInvocationSuffix(String uniqueId) {
+ if (uniqueId == null) {
+ return "";
+ }
+ String marker = "[class-template-invocation:";
Review Comment:
Switched this to UniqueId.parse(uniqueId).getSegments() and read the class-template-invocation / test-template-invocation values from there.
##########
surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java:
##########
@@ -462,14 +498,26 @@ private ResultDisplay toClassMethodName(TestIdentifier testIdentifier) {
.map(TestIdentifier::getLegacyReportingName)
.anyMatch(legacyReportingName -> legacyReportingName.matches("^\\[.+]$"));
boolean isTestTemplate = testIdentifier.getLegacyReportingName().matches("^.*\\[\\d+]$");
-
- boolean parameterized = isParameterized || hasParameterizedParent || isTestTemplate;
+ // JUnit 6 @ParameterizedClass parents have a ClassSource, so they are missed by
+ // hasParameterizedParent, and the method legacy name no longer includes [N] (#3303).
+ String classTemplateInvocationSuffix = extractClassTemplateInvocationSuffix(testIdentifier.getUniqueId());
+
+ boolean parameterized = isParameterized
+ || hasParameterizedParent
+ || isTestTemplate
+ || !classTemplateInvocationSuffix.isEmpty();
String methodName = methodSource.getMethodName();
String description = testIdentifier.getLegacyReportingName();
boolean equalDescriptions = methodDisplay.equals(description);
boolean hasLegacyDescription = description.startsWith(methodName + '(');
boolean hasDisplayName = !equalDescriptions || !hasLegacyDescription;
String methodDesc = parameterized ? description : methodName;
+ // JUnit 6.1+ already puts the class index before a method invocation index
Review Comment:
Yeah, the contains() check was wrong. foo()[2] from method #2 looked like class #2 already, and class #2 / method #1 came out as foo()[1][2]. I rebuild from the unique-id segments now, class index first: class #2 / method #1 is foo()[2][1].
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix #3303: distinguish JUnit 6 ParameterizedClass invocations [maven-surefire]
Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy merged PR #3432:
URL: https://github.com/apache/maven-surefire/pull/3432
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix #3303: distinguish JUnit 6 ParameterizedClass invocations [maven-surefire]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3432:
URL: https://github.com/apache/maven-surefire/pull/3432#discussion_r3781416151
##########
surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java:
##########
@@ -208,6 +208,32 @@ private Stream<TestIdentifier> collectAllTestIdentifiersInHierarchy(TestIdentifi
.orElseGet(Stream::empty);
}
+ /**
+ * Extract the invocation index from a JUnit Jupiter {@code [class-template-invocation:#N]} unique-id
+ * segment. JUnit 6 {@code @ParameterizedClass} uses this segment; the method-level legacy name
+ * no longer carries the {@code [N]} suffix that {@code @ParameterizedTest} still has.
+ *
+ * @param uniqueId the platform unique id string
+ * @return the numeric index, or {@code null} when the id has no class-template invocation
+ */
+ private static String extractClassTemplateInvocationIndex(String uniqueId) {
+ if (uniqueId == null) {
+ return null;
+ }
+ String marker = "[class-template-invocation:";
+ int start = uniqueId.lastIndexOf(marker);
Review Comment:
This keeps only the innermost class-template invocation. JUnit 6 supports nested `@ParameterizedClass` declarations, whose method IDs contain multiple such segments; with the affected legacy names, outer #1/inner #1 and outer #2/inner #1 would both be reported as `method()[1]`, so rerun aggregation can still collapse distinct tests. Collect every class-template invocation index and add a nested regression case.
This issue also appears on line 503 of the same file.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org