olamy commented on code in PR #3342:
URL: https://github.com/apache/maven-surefire/pull/3342#discussion_r3703513368


##########
surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java:
##########
@@ -311,7 +311,34 @@ private TestIdentifier findTopParent(TestIdentifier 
testIdentifier) {
                 // use deprecated method
                 testPlan.getTestIdentifier(
                         testIdentifier.getParentIdObject().get().toString());
-        return !parent.getParentIdObject().isPresent() ? testIdentifier : 
findTopParent(parent);
+        if (!parent.getParentIdObject().isPresent()) {
+            return testIdentifier;
+        }
+        // Inside a Suite the hierarchy contains a nested engine (like 
junit-jupiter under
+        // junit-platform-suite). Stop at that boundary so the test is 
attributed to its real test
+        // class rather than the Suite class. The ClassSource guard keeps 
traversing up for engines
+        // that expose no test class below them (like Cucumber 
features/scenarios), so those tests
+        // fall back to the enclosing Suite class instead of being dropped.
+        if (isEngineIdentifier(parent) && hasClassSource(testIdentifier)) {
+            return testIdentifier;
+        }
+        return findTopParent(parent);
+    }
+
+    private static boolean hasClassSource(TestIdentifier testIdentifier) {
+        return 
testIdentifier.getSource().filter(ClassSource.class::isInstance).isPresent();
+    }
+
+    private static boolean isEngineIdentifier(TestIdentifier testIdentifier) {
+        String uniqueId = testIdentifier.getUniqueId();
+        int lastOpen = uniqueId.lastIndexOf('[');
+        if (lastOpen >= 0) {
+            int colon = uniqueId.indexOf(':', lastOpen);
+            if (colon > lastOpen) {
+                return "engine".equals(uniqueId.substring(lastOpen + 1, 
colon));

Review Comment:
   Is there anything less brittle than relying on this?
   @sormuras any idea how to identify a node being the engine?



-- 
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