From 4896b115d2739a9584eed36c15a5a50ca3fdf6d1 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 1 Aug 2022 12:48:36 +0300 Subject: [PATCH] Ensure CompileWithTargetClassAccessExtension only uses Jupiter TestEngine Commit 9dd7f5412aa72efdeb1ba15b2cd86c6391540b61 (which has now been reverted) addressed the issue of having the TestNG TestEngine for the JUnit Platform on the test runtime classpath by allowing `org.testng` types to pass through to the original ClassLoader; however, that fix merely obfuscated the underlying issue. The underlying issue is that the CompileWithTargetClassAccessExtension is only applicable to JUnit Jupiter tests and therefore should launch the JUnit Platform with only the JUnit Jupiter TestEngine active. This commit addresses this issue by applying an EngineFilter to include only the "junit-jupiter" test engine. Closes gh-28900 --- .../compile/CompileWithTargetClassAccessExtension.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccessExtension.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccessExtension.java index c67e581615..96c3ce4f70 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccessExtension.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/compile/CompileWithTargetClassAccessExtension.java @@ -22,6 +22,7 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.InvocationInterceptor; import org.junit.jupiter.api.extension.ReflectiveInvocationContext; import org.junit.platform.engine.discovery.DiscoverySelectors; +import org.junit.platform.launcher.EngineFilter; import org.junit.platform.launcher.Launcher; import org.junit.platform.launcher.LauncherDiscoveryRequest; import org.junit.platform.launcher.TestPlan; @@ -40,6 +41,7 @@ import org.springframework.util.ReflectionUtils; * * @author Christoph Dreis * @author Phillip Webb + * @author Sam Brannen * @since 6.0 */ class CompileWithTargetClassAccessExtension implements InvocationInterceptor { @@ -134,6 +136,7 @@ class CompileWithTargetClassAccessExtension implements InvocationInterceptor { Method testMethod = findMethod(testClass, testMethodName); LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() .selectors(DiscoverySelectors.selectMethod(testClass, testMethod)) + .filters(EngineFilter.includeEngines("junit-jupiter")) .build(); Launcher launcher = LauncherFactory.create(); TestPlan testPlan = launcher.discover(request);