GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: report AfterAll/AfterClass exceptions as errors again (#3412) by arimu1 · Pull Request #3413 · apache/maven-surefire

Conversation

@arimu1

@arimu1 arimu1 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3412

Since Surefire 3.5.5, exceptions thrown from JUnit @AfterAll / @AfterClass (class-level teardown) were no longer reported as errors. The suite totals showed errors="0", the teardown failure was misclassified as a flake (flakes="1"), and with rerunFailingTestsCount > 0 already-passing test methods were re-executed while the build could stay green.

This regressed when BeforeAll flake handling treated any class-level failure with a null / initializationError name as flaky whenever sibling test methods had succeeded — which is exactly the AfterAll pattern (tests pass, then teardown fails).

Fix

In RunListenerAdapter, distinguish setup vs teardown class-level failures:

When Report name Rerun? Classification
Class fails before any test method succeeds initializationError yes (existing BeforeAll path) may be FLAKE if a later rerun succeeds
Class fails after at least one test method succeeded executionError no always ERROR

Reporter special-casing for flaky BeforeAll is limited to initializationError (and the legacy "null" method name string). executionError goes through the normal error path in DefaultReporterFactory and StatelessXmlReporter.

Manual verification (Temurin 21, installed SNAPSHOT plugin)

@afterall always fails:

Tests run: 3, Failures: 0, Errors: 1  (class)
Tests run: 4, Failures: 0, Errors: 1  (suite)
XML: tests="3" errors="1" flakes="0" name="executionError"
BUILD FAILURE

@afterall + rerunFailingTestsCount=2: passing methods run once (not 3×); still errors="1".

@afterclass (JUnit 4 / vintage): same — executionError, errors="1".

@BeforeAll always fails: still initializationError, errors="1" (unchanged).

Checklist

  • Each commit in the pull request should have a meaningful subject line and body.

  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.

  • Run mvn clean install to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.

  • You have run the integration tests successfully (mvn -Prun-its clean install). (Focused unit tests + manual IT projects exercised; full -Prun-its left to CI.)

  • I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004

Tests

  • DefaultReporterFactoryTest (incl. testAfterAllFailureRemainsErrorNotFlake) — 5/5
  • RunListenerAdapterTest (incl. AfterAll naming / no-rerun) — 34/34
  • JUnitPlatformProviderTest (incl. shouldErrorClassOnAfterAll) — 35/35
  • StatelessXmlReporterTest — 12/12
  • New ITs: JUnit5FailingAfterAllIT, JUnit4FailingAfterClassIT (+ resources)
  • Manual nested projects with SNAPSHOT surefire as above

Related

  • Regression introduced while handling BeforeAll flakes (b4a53de)
  • Prior attempt documenting current broken behavior: Add ITs for AfterAll/AfterClass teardown failure #3338 (ITs only; this PR fixes the behavior)
  • Empty-name fix for container failures: Fix empty and missing testcase entries for JUnit 5 @BeforeAll/@AfterAll failures #3329 (initializationError naming)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@arimu1
fix: report AfterAll/AfterClass exceptions as errors again (apache#3412)
da16ec2
Since 3.5.5, class-level teardown failures (@afterall / @afterclass) were
misclassified as flaky BeforeAll failures whenever any test method in the
same class had succeeded. That made errors disappear from suite totals,
turned deterministic teardown failures into flakes, and needlessly re-ran
already-passing tests when rerunFailingTestsCount was set.

Distinguish setup vs teardown at the JUnit Platform adapter:
- Before any test method succeeds → initializationError (flaky-BeforeAll path)
- After a successful test method → executionError (real error, not re-run)

Keep BeforeAll flake special-casing for initializationError only.

Signed-off-by: arimu1 <[email protected]>
@olamy olamy added the bug Something isn't working label Aug 8, 2026
@olamy olamy added this to the 3.6.0-M2 milestone Aug 8, 2026
@olamy
olamy merged commit 92e6174 into apache:master Aug 8, 2026
14 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot assigned olamy Aug 8, 2026
@olamy olamy mentioned this pull request Aug 12, 2026
Report AfterAll/AfterClass failures as errors, not flakes (#3412) #3427
Merged
6 tasks
olamy added a commit that referenced this pull request Aug 13, 2026
@olamy
Report AfterAll/AfterClass failures as errors, not flakes (#3412) (#3427
b6b2b10
)

Backport of #3413 (da16ec2) from master, adapted for 3.5.x. The JUnit
Platform provider now names post-success container failures
"executionError" so the reporter keeps them as real errors instead of
misclassifying them as flaky @BeforeAll failures.

Signed-off-by: Olivier Lamy <[email protected]>
@olamy olamy mentioned this pull request Aug 28, 2026
Fixing issues of new surefire mode using Junit Platform support-and-care/maven-support-and-care#246
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@olamy olamy

Labels

bug Something isn't working

Projects

None yet

Milestone

3.6.0

Development

Successfully merging this pull request may close these issues.

Exceptions in junit AfterAll / AfterClass are not reported as error since 3.5.5

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@arimu1 @olamy
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.