-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
I'm trying out JUnit 5.10-RC1. The description of the new LauncherInterceptor API on #201 is
... the upcoming 5.10 release will introduce LauncherInterceptor (see #3091 for details) and there's an example for replacing the class loader for all tests in the User Guide.
I'm finding that the interceptor gets called at an early phase in the lifecycle, but setting the TCCL does not seem to affect what classloader is used for test class loading. Is there an extra step I'm missing?
Steps to reproduce
I'm attaching a simple reproducer. It's very similar to the documented example. I make a launcher interceptor which sets a new classloader on the thread context classloader. I can see, from printlns, that the interceptor is being called.
public CustomLauncherInterceptor() throws Exception {
ClassLoader parent = Thread.currentThread().getContextClassLoader();
customClassLoader = new ClassLoader("SuperCustom", parent) {};
}
@Override
public <T> T intercept(Invocation<T> invocation) {
Thread currentThread = Thread.currentThread();
ClassLoader originalClassLoader = currentThread.getContextClassLoader();
currentThread.setContextClassLoader(customClassLoader);
try {
return invocation.proceed();
}
finally {
currentThread.setContextClassLoader(originalClassLoader);
}
}
In my test, I check what classloader the test class was loaded with:
@Test
public void testClassLoader() throws URISyntaxException, IOException, InterruptedException {
String name = this.getClass().getClassLoader().getName();
assertEquals("SuperCustom", name);
}
The test fails:
[ERROR] Failures:
[ERROR] SimpleTest.testClassLoader:13 expected: <SuperCustom> but was: <app>
Resources
Context
- Used versions (Jupiter/Vintage/Platform): Jupiter 5.10.0-RC1
- Build Tool/IDE: Maven/IDEA