Has anybody already tried running JUnit 5 Parametrized tests that use a @MethodSource in Java 11 with bnd?
My tests ran fine with Java 8.
However, switching to Java 11, I got a ClassNotFoundException for the class under test.
Debugging showed that JUnit 5 was trying to look up the class using the thread context class loader (TCCL) which was set to the OSGI ContextFinder and the only CL that one would consider was the CL of the JUnit 5 platform bundle.
If I manually set the TCCL using a @BeforeAll method to the classloader of the class under test, it works.
I was curious if anybody has already run into this or a similar problem.
Problem occurred for me when running the tests using the BND Eclipse Plugins as well as when building on the command line using the BND Maven Plugins.
Hi @rec, thanks for the post (and thanks @pkriens for bringing it to my attention!)
Without seeing the actual test case that is causing the issue I cannot be 100% certain, but based on what you’ve said I’m 90% certain that this is a manifestation of these issues in JUnit:
I think that it will solve your problem. I don’t think this commit has made it into a public release of JUnit yet, but hopefully in the next. In the meantime, the TCCL trick that you did in @BeforeAll should work (as long as you’re un-setting it in @AfterAll), as long as you’re not trying to run JUnit multithreaded. The fix that was committed in PR #3297 should be multi-threaded safe, I think.