ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lucas Bullen <>
Subject ClassLoaders in JUnit Launcher Task
Date Fri, 01 Jun 2018 17:16:23 GMT

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 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.


Thanks for the help or insight in advance.


Lucas Bullen

Software Engineering Intern

Red Hat


90 Eglinton Ave E #502,

Toronto, ON M4P 2Y3

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message