Copilot commented on code in PR #3652:
URL: https://github.com/apache/maven-surefire/pull/3652#discussion_r4731145940
##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java:
##########
@@ -350,18 +351,22 @@ private void mergeTestHistoryResult() {
String testClassMethodName =
entry.getKey().getTestClassMethodName();
// If current test belong to class that failed during beforeAll
store that info to proper log info
String className =
extractClassNameFromMethodName(testClassMethodName);
- if (beforeAllFailures.containsKey(className)) {
- List<TestMethodStats> previousMethodStats =
beforeAllFailures.get(className);
- previousMethodStats.addAll(testMethodStats);
- beforeAllFailures.put(className, previousMethodStats);
+ String qualifiedName =
testMethodStats.get(0).getSourceQualifiedName();
+ for (Map.Entry<String, List<TestMethodStats>> failure :
beforeAllFailures.entrySet()) {
+ // all the failures of one class are reported under the same
class name
+ String failedReportClass =
+
extractClassNameFromMethodName(failure.getValue().get(0).getTestClassMethodName());
+ if (passedAfterBeforeAllFailure(failure.getKey(),
failedReportClass, qualifiedName, className)) {
+ failure.getValue().addAll(testMethodStats);
Review Comment:
When an outer test passes, nested setup fails, and the nested test fails
then passes across two reruns, its history ends up in `flakyTests`. This loop
only considers `successTests`, so it keeps the recovered setup as an error and
fails the build despite the XML reporting a flake. Include matching successful
executions from both maps, without copying method failures into the setup
history, and cover this sequence with a regression.
##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java:
##########
@@ -418,21 +420,34 @@ private TestResultType
getTestResultTypeWithBeforeAllHandling(
// surface with an empty name and must remain errors (#3412).
if (("null".equals(methodName) ||
"initializationError".equals(methodName))
&& (resultType == TestResultType.ERROR || resultType ==
TestResultType.FAILURE)) {
- // Check if any actual test methods succeeded (exclude synthetic
class-level names)
- boolean hasSuccessfulTestMethods =
methodStatistics.values().stream()
- .filter(entries -> !entries.isEmpty()
- &&
isActualTestMethodName(entries.get(0).getName()))
- .anyMatch(entries ->
- entries.stream().anyMatch(reportEntry ->
reportEntry.getReportEntryType() == SUCCESS));
-
- if (hasSuccessfulTestMethods) {
+ // Several nested classes can share this entry: each one that
failed needs a passing test of its own
+ boolean recovered = methodRuns.stream()
+ .filter(run -> run.getReportEntryType() == ERROR ||
run.getReportEntryType() == FAILURE)
+ .allMatch(failed ->
hasPassingTestAfterBeforeAllFailure(failed, methodStatistics));
Review Comment:
If sibling nested classes A and B both fail setup but only A recovers on
rerun, their shared `initializationError` history is classified entirely as an
error. XML then reports no setup flake for A, while `DefaultReporterFactory`
reports one error and one flake. Split setup histories by their original
qualified class in `arrangeMethodStatistics()` before counting and
serialization, preserving existing keys when qualified identity is unavailable,
and add a mixed-recovery sibling regression.
--
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]