Copilot commented on code in PR #3553:
URL: https://github.com/apache/maven-surefire/pull/3553#discussion_r4395353716


##########
surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/TestPlanScannerFilter.java:
##########
@@ -147,11 +147,26 @@ private static boolean hasEngineOtherThanTestNg() {
     private static void collectClassNames(
             TestPlan testPlan, TestIdentifier identifier, Set<String> 
candidates, Set<String> collected) {
 
+        Set<TestIdentifier> children = testPlan.getChildren(identifier);
         Optional<String> className = className(identifier);
-        if (className.isPresent() && candidates.contains(className.get())) {
-            collected.add(className.get());
+        if (className.isPresent()) {
+            if (children.isEmpty() && identifier.isContainer() && 
!identifier.isTest()) {
+                // A childless container survives pruning only because it may 
register tests
+                // dynamically, e.g. a class annotated with 
@ParameterizedClass. A nested class whose
+                // own tests only materialize under such a container collapses 
into this same node
+                // during discovery and never gets an identifier of its own, 
so credit every candidate
+                // this node could be standing in for, not just its exact 
class name.
+                String nestedPrefix = className.get() + "$";
+                for (String candidate : candidates) {
+                    if (candidate.equals(className.get()) || 
candidate.startsWith(nestedPrefix)) {

Review Comment:
   This scans every candidate for each childless container, including ordinary 
`@ParameterizedTest` and `@TestFactory` method containers because `className()` 
also accepts `MethodSource`. With C candidate classes and M such methods, 
collection now performs C × M candidate checks even when there are no nested 
candidates. Index candidates by their enclosing-class prefixes once and look up 
matching descendants during traversal instead of rescanning the full set for 
every container.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to