arturobernalg commented on code in PR #3553:
URL: https://github.com/apache/maven-surefire/pull/3553#discussion_r4397181323
##########
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:
Good catch, and it's actually broader than the nested-class case: any
@ParameterizedTest or @TestFactory method is itself a childless CONTAINER node
at discovery time (invocations/dynamic tests only materialize at execution), so
the rescan was happening per such method, not just per @ParameterizedClass.
Pushed a fix: candidates are now kept in a NavigableSet (sorted), so a
nested match is a tailSet lookup starting right after the outer class name
instead of a full scan -- O(log n) per childless container instead of O(n),
with the common case (no nested candidates) short-circuiting immediately.
Verified against junit-platform-launcher directly that a
@ParameterizedTest/@TestFactory method's identifier is CONTAINER+childless with
no children, confirming this path was hit far more often than just the
@ParameterizedClass scenario. Full suite, checkstyle and spotless still green.
--
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]