Skip to content

Fix nested test class failure detection and version bump to 1.15.#34

Open
sid2700 wants to merge 5 commits intomasterfrom
fix-nested-test-class-bug
Open

Fix nested test class failure detection and version bump to 1.15.#34
sid2700 wants to merge 5 commits intomasterfrom
fix-nested-test-class-bug

Conversation

@sid2700
Copy link

@sid2700 sid2700 commented Mar 9, 2026

Summary

Fixes a bug where test failures in JUnit 5 @Nested inner classes were not retried by the supertest plugin.

Root cause: Surefire 3.x reports nested class test cases inside the outer class's XML report, but uses the @DisplayName (e.g., "AddNumbers Method Tests") as the classname attribute instead of the FQCN. The plugin was building a retry command like -Dtest=OuterClass#nestedMethod*, but surefire's -Dtest filter cannot locate methods that only exist inside nested classes when filtering by the outer class name — resulting in Tests run: 0 on retry.

Fix:

  • SurefireReportParser now detects nested class failures by comparing testcase/@classname against testsuite/@name
  • When a nested class test fails, the entire outer class is rerun without method filtering (-Dtest=OuterClass instead of -Dtest=OuterClass#method*), since surefire has no way to target individual methods inside nested classes
  • Adds a null check for testcase child nodes to prevent NPE on test cases with no failure/error elements
  • createRerunCommand uses getOuterClassName() to correctly track nested class reports (from other surefire versions that generate separate $-prefixed XMLs) against allTestClasses, which excludes inner classes via **/*$*

Version bumped to 1.15.

Test plan

  • Added NestedInnerTest.xml test fixture matching real surefire 3.5.4 output format (nested class tests with display name as classname)
  • Added createRerunCommandWithNestedTestClassFailure test verifying entire outer class is rerun
  • Added testGetOuterClassName unit test
  • Existing tests continue to pass (17/17)

When test classes use JUnit 5 @nested inner classes, surefire generates
separate XML reports with class names like OuterTest$InnerTest. The plugin
was failing to detect these failures because the nested class name didn't
match entries in allTestClasses (which excludes $-classes). The fix resolves
nested class names to their outer class before building the retry command.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@francispereira
Copy link

francispereira commented Mar 9, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

sid2700 and others added 4 commits March 9, 2026 16:12
The previous fix mapped nested class names to the outer class, but surefire
cannot find test methods that only exist in nested classes when filtering by
the outer class name. Keep the full $NestedClass name in -Dtest so surefire
can locate the methods, while still using the outer class for tracking in
allTestClasses/incompleteTests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Surefire 3.x puts nested @nested class tests in the outer class XML report
with a display name as classname, not the FQCN. The -Dtest filter cannot
target methods inside nested classes by name, so when a nested class test
fails, rerun the entire outer class instead of filtering by method.

Also fix NPE when parsing testcase elements with no failure/error children.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sid2700 sid2700 requested a review from judepereira March 10, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants