Skip to content

fix: reuse Jupiter finder for JUnit 6 discovery - #1910

Merged
wenyt (wenytang-ms) merged 2 commits into
mainfrom
fix/junit6-nested-test-discovery
Aug 17, 2026
Merged

fix: reuse Jupiter finder for JUnit 6 discovery#1910
wenyt (wenytang-ms) merged 2 commits into
mainfrom
fix/junit6-nested-test-discovery

Conversation

@wenytang-ms

@wenytang-ms wenyt (wenytang-ms) commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • reuse the inherited Jupiter finder for JUnit 6 test discovery
  • remove the divergent JUnit6TestFinder implementation
  • add regression coverage for package-private, non-static @Nested JUnit 6 classes

Root cause

The custom JUnit 6 finder passed the JUnit 6 kind to CoreTestSearchEngine.isAccessibleClass(). Eclipse JDT currently applies Jupiter's relaxed @Nested accessibility rules only through JUnit5TestFinder, so valid nested classes could be rejected during container discovery and lazy loading.

JUnit 5 and JUnit 6 share the same Jupiter discovery semantics. The JUnit 6 searcher now inherits JUnit5TestFinder while retaining TestKind.JUnit6 and the JUnit 6 JDT kind for runtime selection.

Upstream alignment

JDT LS runs the JUnit support provided by Eclipse JDT's org.eclipse.jdt.junit.core bundle. Eclipse JDT's merged JUnit 6 implementation explicitly shares the JUnit 5 finder while selecting a separate JUnit 6 runtime:

This PR follows that upstream separation: shared Jupiter discovery through JUnit5TestFinder, with the JUnit 6 kind retained for launch/runtime selection.

Validation

.\java-extension\mvnw.cmd -f java-extension\pom.xml clean verify -Dtest=JUnit6TestSearcherTest -Dsurefire.failIfNoSpecifiedTests=false -Declipse.p2.mirrors=false
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

Addresses the test discovery and missing CodeLens portion of #1897. The individual-method launch hang still requires separate verification.

JUnit 5 and JUnit 6 share the same Jupiter discovery semantics. Reuse the established finder so non-static @nested classes receive the relaxed accessibility rules, while retaining the JUnit 6 kind for runtime selection.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f7a1a4d1-b63f-438b-a255-54976b0f5a0b

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes JUnit 6 test discovery by reusing Eclipse JDT’s existing Jupiter (JUnit 5) test finder logic, eliminating a divergent JUnit 6 finder that applied stricter accessibility rules and incorrectly rejected valid @Nested classes.

Changes:

  • Make JUnit6TestSearcher inherit JUnit 5’s finder-based discovery behavior while still reporting TestKind.JUnit6 / JUnit 6 JDT kind IDs for runtime selection.
  • Remove the custom JUnit6TestFinder implementation.
  • Add regression coverage and a minimal workspace project for package-private, non-static @Nested JUnit 6 classes.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/searcher/JUnit6TestSearcher.java Drops custom finder usage and relies on inherited Jupiter discovery, keeping JUnit 6 kind identifiers.
java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/searcher/JUnit6TestFinder.java Removes the divergent JUnit 6 finder implementation that caused incorrect accessibility filtering.
java-extension/com.microsoft.java.test.plugin/META-INF/MANIFEST.MF Exports the searcher package to the test bundle via x-friends so the new test can access searchers.
java-extension/com.microsoft.java.test.plugin.test/src/com/microsoft/java/test/plugin/searcher/JUnit6TestSearcherTest.java Adds a regression test validating discovery of a non-static, package-private @Nested class under JUnit 6.
java-extension/com.microsoft.java.test.plugin.test/projects/junit6-nested/src/test/java/example/NestedTests.java Adds a sample JUnit 6 nested test case used by the regression test.
java-extension/com.microsoft.java.test.plugin.test/projects/junit6-nested/.project Adds Eclipse project metadata for the regression test workspace project.
java-extension/com.microsoft.java.test.plugin.test/projects/junit6-nested/.classpath Adds JDT classpath configuration using JUNIT_CONTAINER/6 for the regression test workspace project.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f7a1a4d1-b63f-438b-a255-54976b0f5a0b

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@wenytang-ms
wenyt (wenytang-ms) marked this pull request as ready for review August 17, 2026 06:58
@wenytang-ms
wenyt (wenytang-ms) merged commit bf9cfac into main Aug 17, 2026
6 checks passed
@wenytang-ms
wenyt (wenytang-ms) deleted the fix/junit6-nested-test-discovery branch August 17, 2026 07: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