diff --git a/common/junit-platform-native/build.gradle b/common/junit-platform-native/build.gradle index 6231a8486..e1883575e 100644 --- a/common/junit-platform-native/build.gradle +++ b/common/junit-platform-native/build.gradle @@ -52,12 +52,19 @@ maven { } dependencies { compileOnly libs.graalvm.svm - implementation(platform(libs.test.junit.bom)) - implementation libs.test.junit.platform.console - implementation libs.test.junit.platform.launcher - implementation libs.test.junit.jupiter.core + compileOnly(platform(libs.test.junit.bom)) + compileOnly libs.test.junit.platform.console + compileOnly libs.test.junit.platform.launcher + compileOnly libs.test.junit.jupiter.core testImplementation libs.test.junit.vintage + + testImplementation libs.test.junit.jupiter.core + + testRuntimeOnly(platform(libs.test.junit.bom)) + testCompileOnly(platform(libs.test.junit.bom)) + testRuntimeOnly libs.test.junit.platform.console testRuntimeOnly libs.test.junit.platform.launcher + testRuntimeOnly libs.test.junit.jupiter.core } apply from: "gradle/native-image-testing.gradle" diff --git a/common/junit-platform-native/src/main/java/org/graalvm/junit/platform/JUnitPlatformFeature.java b/common/junit-platform-native/src/main/java/org/graalvm/junit/platform/JUnitPlatformFeature.java index 5f22314ff..04ad7eb9a 100644 --- a/common/junit-platform-native/src/main/java/org/graalvm/junit/platform/JUnitPlatformFeature.java +++ b/common/junit-platform-native/src/main/java/org/graalvm/junit/platform/JUnitPlatformFeature.java @@ -264,7 +264,13 @@ private static void initializeClassesForJDK21OrEarlier() { try (InputStream is = JUnitPlatformFeature.class.getResourceAsStream("/initialize-at-buildtime")) { if (is != null) { try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { - br.lines().forEach(RuntimeClassInitialization::initializeAtBuildTime); + br.lines().forEach(cls -> { + try { + RuntimeClassInitialization.initializeAtBuildTime(cls); + } catch (NoClassDefFoundError e) { + // if users use older JUnit versions some classes might not be available + } + }); } } } catch (IOException e) { diff --git a/common/junit-platform-native/src/main/java/org/graalvm/junit/platform/NativeImageJUnitLauncher.java b/common/junit-platform-native/src/main/java/org/graalvm/junit/platform/NativeImageJUnitLauncher.java index 5829d6f42..4372adc55 100644 --- a/common/junit-platform-native/src/main/java/org/graalvm/junit/platform/NativeImageJUnitLauncher.java +++ b/common/junit-platform-native/src/main/java/org/graalvm/junit/platform/NativeImageJUnitLauncher.java @@ -123,12 +123,12 @@ public static void main(String... args) { out.println("JUnit Platform on Native Image - report"); out.println("----------------------------------------\n"); out.flush(); - launcher.registerTestExecutionListeners(new PrintTestExecutionListener(out)); + configurePrintTestExecutionListener(launcher, out); } SummaryGeneratingListener summaryListener = new SummaryGeneratingListener(); launcher.registerTestExecutionListeners(summaryListener); - launcher.registerTestExecutionListeners(new LegacyXmlReportGeneratingListener(Paths.get(xmlOutput), out)); + configureLegacyXMLReport(launcher, xmlOutput, out); launcher.execute(testPlan); TestExecutionSummary summary = summaryListener.getSummary(); @@ -271,4 +271,21 @@ private static boolean testIdsDirectoryExists(Path directory) { return directory != null && Files.exists(directory); } + + private static void configurePrintTestExecutionListener(Launcher launcher, PrintWriter out) { + try { + Class.forName("org.junit.platform.reporting.legacy.LegacyReportingUtils"); + launcher.registerTestExecutionListeners(new PrintTestExecutionListener(out)); + } catch (NoClassDefFoundError | ClassNotFoundException e) { + // intentionally ignored + } + } + + private static void configureLegacyXMLReport(Launcher launcher, String xmlOutput, PrintWriter out) { + try { + launcher.registerTestExecutionListeners(new LegacyXmlReportGeneratingListener(Paths.get(xmlOutput), out)); + } catch (NoClassDefFoundError e) { + // intentionally ignored + } + } } diff --git a/common/junit-platform-native/src/main/java/org/graalvm/junit/platform/config/jupiter/JupiterConfigProvider.java b/common/junit-platform-native/src/main/java/org/graalvm/junit/platform/config/jupiter/JupiterConfigProvider.java index f666eba56..894099f12 100644 --- a/common/junit-platform-native/src/main/java/org/graalvm/junit/platform/config/jupiter/JupiterConfigProvider.java +++ b/common/junit-platform-native/src/main/java/org/graalvm/junit/platform/config/jupiter/JupiterConfigProvider.java @@ -54,8 +54,8 @@ import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.params.provider.EnumSource; -import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.FieldSource; +import org.junit.jupiter.params.provider.MethodSource; import java.lang.reflect.Method; import java.util.ArrayList; @@ -86,9 +86,15 @@ public void onTestClassRegistered(Class testClass, NativeImageConfiguration r AnnotationUtils.forEachAnnotatedMethodParameter(testClass, AggregateWith.class, annotation -> registry.registerAllClassMembersForReflection(annotation.value())); AnnotationUtils.forEachAnnotatedMethod(testClass, EnumSource.class, (m, annotation) -> handleEnumSource(m, annotation, registry)); AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, MethodSource.class, JupiterConfigProvider::handleMethodSource); - AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, FieldSource.class, JupiterConfigProvider::handleFieldSource); AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, EnabledIf.class, JupiterConfigProvider::handleEnabledIf); AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, DisabledIf.class, JupiterConfigProvider::handleDisabledIf); + + try { + AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, FieldSource.class, JupiterConfigProvider::handleFieldSource); + } catch (NoClassDefFoundError e) { + // if users use JUnit version older than 5.11, FieldSource class won't be available + } + } private static Class[] handleMethodSource(MethodSource annotation) { diff --git a/common/junit-platform-native/src/main/resources/initialize-at-buildtime b/common/junit-platform-native/src/main/resources/initialize-at-buildtime index 052ceb5f8..0921a7e8b 100644 --- a/common/junit-platform-native/src/main/resources/initialize-at-buildtime +++ b/common/junit-platform-native/src/main/resources/initialize-at-buildtime @@ -46,6 +46,7 @@ org.junit.jupiter.engine.discovery.MethodSelectorResolver$MethodType$3 org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests org.junit.jupiter.engine.discovery.predicates.IsTestFactoryMethod org.junit.jupiter.engine.execution.ConditionEvaluator +org.junit.jupiter.engine.execution.ExecutableInvoker org.junit.jupiter.engine.execution.InterceptingExecutableInvoker org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall$VoidMethodInterceptorCall @@ -78,6 +79,7 @@ org.junit.platform.launcher.core.DiscoveryIssueNotifier org.junit.platform.launcher.core.EngineDiscoveryOrchestrator org.junit.platform.launcher.core.EngineExecutionOrchestrator org.junit.platform.launcher.core.EngineFilterer +org.junit.platform.launcher.core.EngineIdValidator org.junit.platform.launcher.core.HierarchicalOutputDirectoryProvider org.junit.platform.launcher.core.InternalTestPlan org.junit.platform.launcher.core.LauncherConfig @@ -90,6 +92,8 @@ org.junit.platform.launcher.core.LauncherDiscoveryResult org.junit.platform.launcher.core.LauncherDiscoveryResult$EngineResultInfo org.junit.platform.launcher.core.LauncherListenerRegistry org.junit.platform.launcher.core.ListenerRegistry +org.junit.platform.launcher.core.ServiceLoaderRegistry +org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry org.junit.platform.launcher.core.SessionPerRequestLauncher org.junit.platform.launcher.EngineDiscoveryResult org.junit.platform.launcher.LauncherSessionListener$1 diff --git a/native-maven-plugin/reproducers/issue-144/pom.xml b/native-maven-plugin/reproducers/issue-144/pom.xml index a64e06846..ea844b8a1 100644 --- a/native-maven-plugin/reproducers/issue-144/pom.xml +++ b/native-maven-plugin/reproducers/issue-144/pom.xml @@ -69,6 +69,12 @@ ${junit.jupiter.version} test + + org.junit.platform + junit-platform-launcher + 1.11.0 + test + diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeTestMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeTestMojo.java index 9b7fc7289..dec5ebbdb 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeTestMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeTestMojo.java @@ -60,7 +60,6 @@ import org.eclipse.aether.resolution.DependencyRequest; import org.eclipse.aether.resolution.DependencyResolutionException; import org.eclipse.aether.resolution.DependencyResult; -import org.graalvm.buildtools.utils.FileUtils; import org.graalvm.buildtools.utils.JUnitUtils; import org.graalvm.buildtools.utils.NativeImageConfigurationUtils; @@ -76,7 +75,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; diff --git a/samples/java-application-with-custom-tests/build.gradle b/samples/java-application-with-custom-tests/build.gradle index c6e4a8fbe..5939374fa 100644 --- a/samples/java-application-with-custom-tests/build.gradle +++ b/samples/java-application-with-custom-tests/build.gradle @@ -62,12 +62,15 @@ sourceSets { configurations { integTestImplementation.extendsFrom(testImplementation) + integTestRuntimeOnly.extendsFrom(testRuntimeOnly) } dependencies { testImplementation(platform("org.junit:junit-bom:${junitVersion}")) testImplementation('org.junit.jupiter:junit-jupiter') integTestImplementation project(":") + testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.0") + testRuntimeOnly("org.junit.platform:junit-platform-reporting:1.11.0") } def integTest = tasks.register("integTest", Test) { diff --git a/samples/java-application-with-reflection/build.gradle b/samples/java-application-with-reflection/build.gradle index a13580cb8..d20401f55 100644 --- a/samples/java-application-with-reflection/build.gradle +++ b/samples/java-application-with-reflection/build.gradle @@ -58,6 +58,7 @@ def junitVersion = providers.gradleProperty('junit.jupiter.version') dependencies { testImplementation(platform("org.junit:junit-bom:${junitVersion}")) testImplementation('org.junit.jupiter:junit-jupiter') + testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.0") } test { diff --git a/samples/java-application-with-reflection/pom.xml b/samples/java-application-with-reflection/pom.xml index c68d4e8a9..338255ce4 100644 --- a/samples/java-application-with-reflection/pom.xml +++ b/samples/java-application-with-reflection/pom.xml @@ -65,6 +65,12 @@ ${junit.jupiter.version} test + + org.junit.platform + junit-platform-launcher + 1.11.0 + test + diff --git a/samples/java-application-with-resources/build.gradle b/samples/java-application-with-resources/build.gradle index b8b2ca6f8..d01b883df 100644 --- a/samples/java-application-with-resources/build.gradle +++ b/samples/java-application-with-resources/build.gradle @@ -58,6 +58,7 @@ def junitVersion = providers.gradleProperty('junit.jupiter.version') dependencies { testImplementation(platform("org.junit:junit-bom:${junitVersion}")) testImplementation('org.junit.jupiter:junit-jupiter') + testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.0") } test { diff --git a/samples/java-application-with-resources/pom.xml b/samples/java-application-with-resources/pom.xml index 95fd47f4c..8e8e6afc6 100644 --- a/samples/java-application-with-resources/pom.xml +++ b/samples/java-application-with-resources/pom.xml @@ -70,6 +70,12 @@ ${junit.jupiter.version} test + + org.junit.platform + junit-platform-launcher + 1.11.0 + test + diff --git a/samples/java-application-with-tests/build.gradle b/samples/java-application-with-tests/build.gradle index 4be9055f5..2f7cf9d2e 100644 --- a/samples/java-application-with-tests/build.gradle +++ b/samples/java-application-with-tests/build.gradle @@ -58,6 +58,8 @@ def junitVersion = providers.gradleProperty('junit.jupiter.version') dependencies { testImplementation(platform("org.junit:junit-bom:${junitVersion}")) testImplementation('org.junit.jupiter:junit-jupiter') + testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.0") + testRuntimeOnly("org.junit.platform:junit-platform-reporting:1.11.0") } test { diff --git a/samples/java-application-with-tests/pom.xml b/samples/java-application-with-tests/pom.xml index 19b088af7..02b17befd 100644 --- a/samples/java-application-with-tests/pom.xml +++ b/samples/java-application-with-tests/pom.xml @@ -71,6 +71,12 @@ ${junit.jupiter.version} test + + org.junit.platform + junit-platform-launcher + 1.11.0 + test + diff --git a/samples/java-library/build.gradle b/samples/java-library/build.gradle index 0b9c4d818..3689f9abb 100644 --- a/samples/java-library/build.gradle +++ b/samples/java-library/build.gradle @@ -54,6 +54,7 @@ def junitVersion = providers.gradleProperty('junit.jupiter.version') dependencies { testImplementation(platform("org.junit:junit-bom:${junitVersion}")) testImplementation('org.junit.jupiter:junit-jupiter') + testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.0") } graalvmNative { diff --git a/samples/java-library/pom.xml b/samples/java-library/pom.xml index 52acbb800..644b989d2 100644 --- a/samples/java-library/pom.xml +++ b/samples/java-library/pom.xml @@ -63,6 +63,12 @@ ${junit.jupiter.version} test + + org.junit.platform + junit-platform-launcher + 1.11.0 + test + diff --git a/samples/junit-tests/build.gradle b/samples/junit-tests/build.gradle index 0e5021ca1..6a2e1b659 100644 --- a/samples/junit-tests/build.gradle +++ b/samples/junit-tests/build.gradle @@ -51,6 +51,7 @@ repositories { dependencies { testImplementation 'org.junit.jupiter:junit-jupiter:5.11.0' testImplementation "org.junit.vintage:junit-vintage-engine:5.11.0" + testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.0") } application { diff --git a/samples/junit-tests/pom.xml b/samples/junit-tests/pom.xml index 9cdc96369..54b5e5583 100644 --- a/samples/junit-tests/pom.xml +++ b/samples/junit-tests/pom.xml @@ -64,6 +64,12 @@ ${junit.jupiter.version} test + + org.junit.platform + junit-platform-launcher + 1.11.0 + test + org.junit.vintage junit-vintage-engine diff --git a/samples/kotlin-application-with-tests/build.gradle b/samples/kotlin-application-with-tests/build.gradle index e69823512..3fd93ea08 100644 --- a/samples/kotlin-application-with-tests/build.gradle +++ b/samples/kotlin-application-with-tests/build.gradle @@ -54,6 +54,10 @@ dependencies { implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' testImplementation 'org.jetbrains.kotlin:kotlin-test' + testRuntimeOnly(platform("org.junit:junit-bom:5.11.0")) + testRuntimeOnly("org.junit.platform:junit-platform-console:1.11.0") + testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.0") + testRuntimeOnly("org.junit.jupiter:junit-jupiter") } application { diff --git a/samples/multi-project-with-tests/core/build.gradle b/samples/multi-project-with-tests/core/build.gradle index 64c80da81..1973ae20a 100644 --- a/samples/multi-project-with-tests/core/build.gradle +++ b/samples/multi-project-with-tests/core/build.gradle @@ -59,6 +59,7 @@ dependencies { implementation(project(":utils")) testImplementation(platform("org.junit:junit-bom:${junitVersion}")) testImplementation('org.junit.jupiter:junit-jupiter') + testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.0") } test { diff --git a/samples/multi-project-with-tests/pom.xml b/samples/multi-project-with-tests/pom.xml index 1ef97757b..836f1d837 100644 --- a/samples/multi-project-with-tests/pom.xml +++ b/samples/multi-project-with-tests/pom.xml @@ -71,6 +71,12 @@ ${junit.jupiter.version} test + + org.junit.platform + junit-platform-launcher + 1.11.0 + test +