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..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 @@ -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, + TestFrameworkUtils.JUNIT5_TEST_SEARCHER.getJdtTestKind()); + } + 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",