According to the Junit documentation, the way to set a custom classloader for tests in Junit 5 is to create a LauncherInterceptor and configure it using by setting a system property e.g. in gradle:
test {
systemProperty(”junit.platform.launcher.interceptors.enabled“, true)
// ...
}
Then then LauncherInterceptor needs to be registered by adding it to /META-INF/services/org.junit.platform.launcher.LauncherDiscoveryListener