git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ClassLoaders in JUnit Launcher Task


Hello,

I'm attempting to use the JUnit 5 Platform Launcher API to upgrade our
testing process to allow for JUnit 5 tests. To minimize the required
changes in the rest of our work flow, I am planning on using Ant's
JUnitLauncherTask [1] which brought with it legacy test result formatters.
With these legacy test result formatters, no changes would have to be made
to the result processing and displaying processes.

However, when attempting to do this I run into an issue with ClassLoaders.
JUnitLauncherTask.execute() [2] sets the thread's ClassLoader to its own or
to an AntClassLoader, both of which do not contain the junit TestEngine's
which causes a Preconditions exception in the constructor of JUnit's
DefaultLauncher due to finding no Launchers [3].

Our previous way of getting around this was to create our own ClassLoader
with the required TestEngines and set this to the current thread's
ClassLoader to ensure that the TestEngines are found [4].

This technique no longer works for the JUnitLauncherTask as it resets the
ClassLoader right before executing the tests. Does anyone have a suggestion
on how to resolve this issue?

My two working plans are to either copy over the necessary files from
org.apache.tools.ant.taskdefs.optional.junitlauncher and remove it's
ClassLoader manipulation code so that I can use my own ClassLoader, or to
use reflection to access the addClass method of the JUnitLauncherTask's
ClassLoader and add our classes. First plan I know works but
copying/maintaining that much code is no good; second plan I haven't gotten
to work yet, but even if I can it is rather hacky.

[1] https://github.com/apache/ant/pull/60/
[2]
https://github.com/apache/ant/blob/342bf00579318f00b373e86a148af984bc7d6acb/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTask.java#L71
[3]
https://github.com/junit-team/junit5/blob/6b4de716ba3b0b46c847e340e2f68954d0cc6192/junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/DefaultLauncher.java#L54
[4]
https://git.eclipse.org/c/pde/eclipse.pde.ui.git/tree/ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/RemotePluginTestRunner.java?h=BETA_JUNIT5#n226

Thanks for the help or insight in advance.

-- 

Lucas Bullen

Software Engineering Intern

Red Hat

<https://www.redhat.com>

90 Eglinton Ave E #502,

Toronto, ON M4P 2Y3

lbullen@xxxxxxxxxx
<https://red.ht/sig>