Skip to content

Commit

Permalink
Ensure CompileWithTargetClassAccessExtension only uses Jupiter TestEn…
Browse files Browse the repository at this point in the history
…gine

Commit 9dd7f54 (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
  • Loading branch information
sbrannen committed Aug 1, 2022
1 parent b89b6bd commit 4896b11
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand All @@ -40,6 +41,7 @@
*
* @author Christoph Dreis
* @author Phillip Webb
* @author Sam Brannen
* @since 6.0
*/
class CompileWithTargetClassAccessExtension implements InvocationInterceptor {
Expand Down Expand Up @@ -134,6 +136,7 @@ private void runTest(ClassLoader classLoader, String testClassName,
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);
Expand Down

0 comments on commit 4896b11

Please sign in to comment.