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 empty and missing testcase entries for JUnit 5 @BeforeAll/@AfterAll failures by MilanTyagi2004 · Pull Request #3329 · apache/maven-surefire

Conversation

@MilanTyagi2004

@MilanTyagi2004 MilanTyagi2004 commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Problem

JUnit 5 container-level failures (e.g., @BeforeAll / @AfterAll) are not handled correctly by Surefire.

  • FAILED containers produce <testcase name=""> due to missing method context
  • ABORTED containers do not emit any <testcase>, causing missing entries in XML reports

Solution

  • Assign fallback name "initializationError" when no method name is available for container failures
  • Emit testAssumptionFailure for ABORTED containers to ensure skipped testcases are generated
  • Preserve existing behavior for normal test methods and engine/root containers

Result

  • No empty testcase names
  • No missing testcases for container-level failures
  • Correct XML reporting for both FAILED and ABORTED scenarios

Tests

  • Updated RunListenerAdapterTest to cover:
    • FAILED container case
    • ABORTED container case

[x] I hereby declare this contribution to be licensed under the Apache License 2.0

Sorry, something went wrong.

Uh oh!

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

All reactions
@MilanTyagi2004
Fix: JUnit 5 @BeforeAll and @afterall failures produce empty testcase…
d43468f
… name
@MilanTyagi2004 MilanTyagi2004 mentioned this pull request Mar 19, 2026
Junit tests failing during @BeforeClass methods have inaccurate xml report #3267
Closed
@olamy

olamy commented Mar 21, 2026

Copy link
Copy Markdown
Member

Thanks for your contribution.
Would it be possible to an IT test for this as well.

All reactions

Sorry, something went wrong.

Uh oh!

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

@olamy olamy linked an issue Mar 21, 2026 that may be closed by this pull request
Junit tests failing during @BeforeClass methods have inaccurate xml report #3267
Closed
@MilanTyagi2004
Update tests for container-level failures with initializationError
aeb5613
@MilanTyagi2004

MilanTyagi2004 commented Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback.

Yes, I will add an integration test to cover this scenario and update the PR.

All reactions

Sorry, something went wrong.

Uh oh!

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

@MilanTyagi2004
Add Integration Test for JUnit 5 @BeforeAll container failure
aeb7fe6
olamy
olamy requested changes Mar 23, 2026
View reviewed changes
Comment thread ...junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java Outdated
&& testExecutionResult.getStatus() != org.junit.platform.engine.TestExecutionResult.Status.SUCCESSFUL
&& testIdentifier.isContainer()
&& methodName == null) {
methodName = "initializationError";

@olamy olamy Mar 23, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this a class constant?

Sorry, something went wrong.

Uh oh!

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

All reactions
@olamy

olamy commented Mar 23, 2026

Copy link
Copy Markdown
Member

Thanks for the feedback.

Yes, I will add an integration test to cover this scenario and update the PR.

Thanks a lot for this. Just a small comment.

All reactions

Sorry, something went wrong.

Uh oh!

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

@MilanTyagi2004

MilanTyagi2004 commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

sure

Thanks for the feedback.
Yes, I will add an integration test to cover this scenario and update the PR.

Thanks a lot for this. Just a small comment.

sure

All reactions

Sorry, something went wrong.

Uh oh!

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

@MilanTyagi2004
Use class constant for initializationError
b53e5d8
@MilanTyagi2004

MilanTyagi2004 commented Mar 23, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Hi @olamy , i am checking why ci/cd fail . give me some time.

olamy reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@MilanTyagi2004
fix CI?CD
9955ef7
@MilanTyagi2004

MilanTyagi2004 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

hi @olamy i fix the ci/cd failure . and test locally using mvn -B clean verify -Prun-its and build success.

would appreciate your review when you have time.
Thanks

All reactions

Sorry, something went wrong.

Uh oh!

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

@XN137

XN137 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

thanks for fixing this!

to add another datapoint:
we are running our tests with <rerunFailingTestsCount>3</rerunFailingTestsCount> and recently added a test that deterministically fails in the teardown method:

  @AfterClass
  public static void tearDown() throws Exception {
     ...
  }

the surefire output looks like this:

[2026-03-27T09:10:32.374Z] [WARNING] Flakes: 
[2026-03-27T09:10:32.374Z] [WARNING] com.mycompany.MyTestClass.<beforeAll>
[2026-03-27T09:10:32.374Z] [ERROR]   Run 1: MyTestClass.tearDown:141 ? NullPointer
[2026-03-27T09:10:32.374Z] [ERROR]   Run 2: MyTestClass.tearDown:141 ? NullPointer
[2026-03-27T09:10:32.374Z] [ERROR]   Run 3: MyTestClass.tearDown:141 ? NullPointer
[2026-03-27T09:10:32.374Z] [ERROR]   Run 4: MyTestClass.tearDown:141 ? NullPointer
[2026-03-27T09:10:32.374Z] [INFO]   Run 5: PASS
[2026-03-27T09:10:32.374Z] [INFO]   Run 6: PASS
[2026-03-27T09:10:32.374Z] [INFO]   Run 7: PASS
[2026-03-27T09:10:32.374Z] [INFO]   Run 8: PASS
[2026-03-27T09:10:32.374Z] [INFO] 
[2026-03-27T09:10:32.374Z] [INFO] 
[2026-03-27T09:10:32.374Z] [WARNING] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Flakes: 1

so no errors are being reported and the jenkins junit report also shows no problems, but the single test method in the class is reported "passed" 4 times.

since this seems pretty serious, i would kindly ask for a new surefire release once this fix is in, thank you!

All reactions

Sorry, something went wrong.

Uh oh!

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

@XN137

XN137 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

i just realized, my test is not junit5 based i.e. using @AfterClass from junit4.
makes me wonder whether the problem is not specific to junit5 ?
would it make sense to have a specific test for failures in test teardown i.e. @AfterAll and @AfterClass ? also cover junit4 ?

All reactions

Sorry, something went wrong.

Uh oh!

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

@MilanTyagi2004

MilanTyagi2004 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

@XN137 ,
image
i think these are the test cases you are talking about

All reactions

Sorry, something went wrong.

Uh oh!

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

@XN137

XN137 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

@MilanTyagi2004 is that a new test your are adding or an existing one (didnt find it on master)?
if the former yeah looks in the right direction, but it would mean this PR isnt specific about junit5 but all kind of setup/teardown errors?

All reactions

Sorry, something went wrong.

Uh oh!

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

@MilanTyagi2004

MilanTyagi2004 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

this is new test i just added to make sure every thing is on right right direction

XN137 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@MilanTyagi2004

MilanTyagi2004 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

@olamy
could you please check these and review this.

olamy reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@MilanTyagi2004

MilanTyagi2004 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

@XN137 could you please tell me what i should do . should we create separate another pr for this.

All reactions

Sorry, something went wrong.

Uh oh!

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

@XN137

XN137 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

@MilanTyagi2004 i am just a regular surefire user, so i can't tell you what you should do to be honest 😅

it also kind of depends on the findings with your added test.
if you realized that the problem of missing testcases not only happens on junit5 but also on junit4, then we should consider extending the scope of this PR.

alternatively, we should file a dedicated issue mentioning both junit4 and 5 and then this PR can keep the junit5 scope and we will need to follow-up with a fix and tests for the junit4 cases.

if your tests found no problems with junit4, you can ignore all my comments and we will need to investigate this separately.

what this PR is missing even if its only for junit5:

  • fix unrelated reformatting in surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
  • add junit5 test that covers exceptions in @AfterAll.
All reactions

Sorry, something went wrong.

Uh oh!

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

@MilanTyagi2004

MilanTyagi2004 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

@MilanTyagi2004 i am just a regular surefire user, so i can't tell you what you should do to be honest 😅

it also kind of depends on the findings with your added test. if you realized that the problem of missing testcases not only happens on junit5 but also on junit4, then we should consider extending the scope of this PR.

alternatively, we should file a dedicated issue mentioning both junit4 and 5 and then this PR can keep the junit5 scope and we will need to follow-up with a fix and tests for the junit4 cases.

if your tests found no problems with junit4, you can ignore all my comments and we will need to investigate this separately.

what this PR is missing even if its only for junit5:

  • fix unrelated reformatting in surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
  • add junit5 test that covers exceptions in @AfterAll.

sure we can discuss the junit4 issues in another pr.

for RunListenerAdapter.java changes are needed to pass error to xml.

, and i understand but before adding Junit 5 test which cover @AfterAll i am waiting for the review from "olamy". Hope you understand.

All reactions

Sorry, something went wrong.

Uh oh!

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

@olamy

olamy commented Mar 28, 2026

Copy link
Copy Markdown
Member

well with master this should be handled the same way in case of junit 4 or 5 (if vintage engine is doing the right thing)
@XN137 ideally you can provide an it test for master branch to see how it goes
this could be different with 3.5.x branch though
but yeah definitely need another PR

All reactions

Sorry, something went wrong.

Uh oh!

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

@MilanTyagi2004

MilanTyagi2004 commented Mar 28, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

@olamy is there any thing i nned to add in this pr.

All reactions

Sorry, something went wrong.

Uh oh!

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

@XN137 XN137 mentioned this pull request Mar 29, 2026
Add ITs for AfterAll/AfterClass teardown failure #3338
Closed
1 task done
@olamy olamy added the bug Something isn't working label Mar 30, 2026
@olamy
olamy merged commit 479bf20 into apache:master Mar 30, 2026
14 checks passed

Uh oh!

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

@github-actions github-actions Bot added this to the 3.6.0.M1 milestone Mar 30, 2026
@github-actions github-actions Bot assigned olamy Mar 30, 2026
@MilanTyagi2004
MilanTyagi2004 deleted the fix-junit5-container-failure-testcase-name branch June 1, 2026 16:26
@arimu1 arimu1 mentioned this pull request Aug 5, 2026
fix: report AfterAll/AfterClass exceptions as errors again (#3412) #3413
Merged
4 of 5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@olamy olamy olamy requested changes

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

Development

Successfully merging this pull request may close these issues.

Junit tests failing during @BeforeClass methods have inaccurate xml report

Uh oh!

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

3 participants

@MilanTyagi2004 @olamy @XN137
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.