Repository navigation
Fixes #3264 : tests inside @Suite incorrectly classified as flakes - #3342
Conversation
fabffc2 to
878db1d
Compare
|
Hi @olamy , any chance you could have a look at this? π |
|
@olamy it looks that there are some failures - unrelated to the changes. Would it be fine to proceed? |
|
I have the same failure locally using Output |
|
Thanks @olamy. I guess I initially ran the IT with older version than 17. I fixed it and add a unit test for it. |
|
@olamy , any chance you could check now that the pipeline is green? |
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect test attribution when rerunFailingTestsCount is used with JUnit Platform @Suite, where tests from different classes could be merged under the Suite class name (leading to real failures being misclassified as flakes). The change updates RunListenerAdapter.findTopParent() to stop traversal at nested engine boundaries inside Suites so the reported source class remains the real test class (while still falling back to the Suite class for engines that donβt expose class-level sources, e.g., Cucumber).
Changes:
- Update
RunListenerAdapter.findTopParent()to stop at nested engine boundaries inside a Suite when aClassSourceis present. - Add unit coverage simulating Suite β nested engine (Jupiter) and Suite β nested engine (Cucumber-like, no
ClassSource) hierarchies. - Update an integration test expectation to match the new XML report file naming/attribution behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java | Adjusts top-parent detection to avoid attributing nested-engine tests to the enclosing Suite class when a real test class is available. |
| surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTest.java | Adds unit tests covering Suite-with-nested-engine attribution for both Jupiter-style and Cucumber-style hierarchies. |
| surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1787JUnit45IT.java | Updates the expected Surefire XML report filename/classname attribution for the JUnit 5 Suite integration scenario. |
| if (lastOpen >= 0) { | ||
| int colon = uniqueId.indexOf(':', lastOpen); | ||
| if (colon > lastOpen) { | ||
| return "engine".equals(uniqueId.substring(lastOpen + 1, colon)); |
There was a problem hiding this comment.
Is there anything less brittle than relying on this?
@sormuras any idea how to identify a node being the engine?
There was a problem hiding this comment.
Mh, there's no direct API like UniqueId::isEngine in https://docs.junit.org/6.1.2/api/org.junit.platform.engine/org/junit/platform/engine/UniqueId.html ... π€
@marcphilipp Any idea?
There was a problem hiding this comment.
Does this help?
testIdentifier.getUniqueIdObject().getLastSegment().isEngine()
There was a problem hiding this comment.
However, that API was introduced in 6.1.1. You can check for "engine".equals(segment.getType()), though, in earlier versions.
When
rerunFailingTestsCountis used with JUnit Platform@Suite, tests from different classes that share a method name are merged under the Suite class name. It causes real failures to be misclassified as flakes. With the changes in the PR,findTopParent()now stops at engine boundaries (parents with noClassSource), correctly attributing tests to their actual class while preserving@Nested.Following this checklist to help us incorporate your contribution quickly and easily:
mvn clean installto make sure basic checks pass. A more thorough check will be performed on your pull request automatically.mvn -Prun-its clean install).If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.