Skip to content

Commit

Permalink
docs: Issue #269 DSpot should set the thread context classloader (#278)
Browse files Browse the repository at this point in the history
* add comments to explain the `Thread.currentThread().setContextClassLoader()`
  • Loading branch information
vmassol authored and danglotb committed Dec 12, 2017
1 parent f4a9cdc commit 64af74c
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ public TestListener run(Class<?> testClass, Collection<String> testMethodNames,
RunNotifier runNotifier = new RunNotifier();
Arrays.stream(additionalListeners).forEach(runNotifier::addListener);
runNotifier.addFirstListener(listener);

// Since we want to use our custom ClassLoader to run the tests of the project being executed by DSpot,
// and since we create a new thread for starting the JUnit Runner, we need to set the context ClassLoader
// to be our custom ClassLoader. This is so that any code in the tests or triggered by the test that uses
// the context ClassLoader will work.
// As an example if the tests call some code that uses Java's ServiceLoader then it would fail to find and
// load any provider located in our custom ClassLoader.
Thread.currentThread().setContextClassLoader(this.classLoader);

runner.run(runNotifier);
});
try {
Expand Down

0 comments on commit 64af74c

Please sign in to comment.