Set thread context class loader to user bundle, for JUnit
@@ -106,12 +106,18 @@ public class JunitRunner extends AbstractComponent implements TestRunner {
if (testClasses == null)
return null;
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
testRuntimeProvider.initialize(testConfig);
TestReportGeneratingListener testReportListener = new TestReportGeneratingListener(suite,
record -> logRecords.put(record.getSequenceNumber(), record),
stdoutTee,
stderrTee,
clock);
+
+ if ( ! testClasses.isEmpty())
+ Thread.currentThread().setContextClassLoader(testClasses.get(0).getClassLoader());
+
LauncherDiscoveryRequest discoveryRequest = LauncherDiscoveryRequestBuilder.request()
.selectors(testClasses.stream()
.map(DiscoverySelectors::selectClass)
@@ -121,6 +127,10 @@ public class JunitRunner extends AbstractComponent implements TestRunner {
return testReportListener.report();
}
+ finally {
+ Thread.currentThread().setContextClassLoader(contextClassLoader);
+ }
+ }
@Override
public void deconstruct() {
