From c95d6672070420a096beb5b3af60879f722f20ea Mon Sep 17 00:00:00 2001 From: wenytang-ms Date: Wed, 25 Feb 2026 17:15:06 +0800 Subject: [PATCH 1/2] fix: fix junit 6 identify --- .../test/plugin/util/TestSearchUtils.java | 26 ++++++++++++++++--- package.json | 12 ++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/TestSearchUtils.java b/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/TestSearchUtils.java index c8542223..0e7447d2 100644 --- a/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/TestSearchUtils.java +++ b/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/TestSearchUtils.java @@ -183,7 +183,8 @@ public static List findTestPackagesAndTypes(List arguments } else { // 1. We suppose a class can only use one test framework // 2. If more accurate kind is available, use it. - if (classItem.getTestKind() == TestKind.JUnit5 && kind == TestKind.JUnit) { + if ((classItem.getTestKind() == TestKind.JUnit5 || + classItem.getTestKind() == TestKind.JUnit6) && kind == TestKind.JUnit) { classItem.setTestKind(TestKind.JUnit); } } @@ -386,7 +387,20 @@ private static void findTestItemsInTypeBinding(ITypeBinding typeBinding, JavaTes final List testMethods = new LinkedList<>(); searchers = searchers.stream().filter(s -> { try { - return CoreTestSearchEngine.isAccessibleClass(type, s.getJdtTestKind()); + if (CoreTestSearchEngine.isAccessibleClass(type, s.getJdtTestKind())) { + return true; + } + // For JUnit 6, Eclipse JDT's isAccessibleClass() only applies the + // relaxed @Nested class rules (non-static, non-public inner classes) + // when testKindId equals JUNIT5_TEST_KIND_ID. For JUNIT6_TEST_KIND_ID, + // it falls into the else branch requiring static + public, which + // incorrectly rejects valid @Nested test classes. Fall back to + // JUnit 5 accessibility check since JUnit 6 shares the same rules. + if (s.getTestKind() == TestKind.JUnit6) { + return CoreTestSearchEngine.isAccessibleClass(type, + org.eclipse.jdt.internal.junit.launcher.TestKindRegistry.JUNIT5_TEST_KIND_ID); + } + return false; } catch (JavaModelException e) { return false; } @@ -425,9 +439,15 @@ private static void findTestItemsInTypeBinding(ITypeBinding typeBinding, JavaTes .build(); } else if (TestFrameworkUtils.JUNIT5_TEST_SEARCHER.isTestClass(type)) { // to handle @Nested and @Testable classes + // Determine whether it's JUnit 6 or JUnit 5 based on project-level detection, + // since JUnit 6 extends JUnit 5 and both searchers match the same annotations. + final List projectKinds = TestKindProvider.getTestKindsFromCache( + type.getJavaProject()); + final TestKind kind = projectKinds.contains(TestKind.JUnit6) ? + TestKind.JUnit6 : TestKind.JUnit5; classItem = new JavaTestItemBuilder().setJavaElement(type) .setLevel(TestLevel.CLASS) - .setKind(TestKind.JUnit5) + .setKind(kind) .build(); } } diff --git a/package.json b/package.json index a3d4bb62..da2bdce2 100644 --- a/package.json +++ b/package.json @@ -56,18 +56,18 @@ "contributes": { "javaExtensions": [ "./server/com.microsoft.java.test.plugin-0.43.1.jar", - "./server/junit-jupiter-api_5.14.1.jar", + "./server/junit-jupiter-api_5.14.3.jar", "./server/junit-jupiter-api_6.0.1.jar", - "./server/junit-jupiter-engine_5.14.1.jar", + "./server/junit-jupiter-engine_5.14.3.jar", "./server/junit-jupiter-engine_6.0.1.jar", "./server/junit-jupiter-migrationsupport_5.14.1.jar", - "./server/junit-jupiter-params_5.14.1.jar", + "./server/junit-jupiter-params_5.14.3.jar", "./server/junit-jupiter-params_6.0.1.jar", - "./server/junit-platform-commons_1.14.1.jar", + "./server/junit-platform-commons_1.14.3.jar", "./server/junit-platform-commons_6.0.1.jar", - "./server/junit-platform-engine_1.14.1.jar", + "./server/junit-platform-engine_1.14.3.jar", "./server/junit-platform-engine_6.0.1.jar", - "./server/junit-platform-launcher_1.14.1.jar", + "./server/junit-platform-launcher_1.14.3.jar", "./server/junit-platform-launcher_6.0.1.jar", "./server/junit-platform-runner_1.14.1.jar", "./server/junit-platform-suite-api_1.14.1.jar", From 0c3ef82ad5d090586e33dab8bfe15dc4335dac4c Mon Sep 17 00:00:00 2001 From: wenytang-ms Date: Thu, 26 Feb 2026 09:46:38 +0800 Subject: [PATCH 2/2] fix: update --- .../com/microsoft/java/test/plugin/util/TestSearchUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/TestSearchUtils.java b/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/TestSearchUtils.java index 0e7447d2..6a3ca250 100644 --- a/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/TestSearchUtils.java +++ b/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/TestSearchUtils.java @@ -398,7 +398,7 @@ private static void findTestItemsInTypeBinding(ITypeBinding typeBinding, JavaTes // JUnit 5 accessibility check since JUnit 6 shares the same rules. if (s.getTestKind() == TestKind.JUnit6) { return CoreTestSearchEngine.isAccessibleClass(type, - org.eclipse.jdt.internal.junit.launcher.TestKindRegistry.JUNIT5_TEST_KIND_ID); + TestFrameworkUtils.JUNIT5_TEST_SEARCHER.getJdtTestKind()); } return false; } catch (JavaModelException e) {