HelloLucas,

On 01/06/18 10:46 PM, Lucas Bullen wrote:

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 test engine are you using and where are the jars for those located? The vintage and the jupiter test engines (part of JUnit 5) or any test engine for that matter, can be placed in the ANT_HOME/lib directory and they should be picked up. Or you can pass the -lib option while launching Ant to pass the location of those jars. These methods have been noted in the documentation of the task[1]

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?

The way JUnit 5 works, it uses the thread context classloader to find the test engines (and even test cases). That's why the JUnitLauncherTask sets it up in a manner that the right classloader is setup before executing the tests.

I looked at the customer classloader you pointed to, in your footnotes. How was that being setup in the Ant build, previously?

Overall, if I understand your question correctly - you do not want to add the *test engines* to the ANT_HOME/lib and neither do you want to pass the -lib option while launching Ant and instead want to define a classpath in your build file and use that classpath for finding the test engines? If that's the case, then yes it's currently a limitation (one that which Stefan had rightly brought up very early in the dev cycle of this task). I do plan to tackle this in a better way, but given the complexity involved with classloaders (both due to the nature of JUnit 5 and Ant itself) and the fact that I  lost focus on this task for a bit, I haven't been able to come up with a solution. I'll look more into this in the upcoming days and see how we can improve this.

If I misunderstood your use case, please do let us know.

[1] https://ant.apache.org/manual/Tasks/junitlauncher.html

-Jaikiran

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org
For additional commands, e-mail: dev-h...@ant.apache.org

Reply via email to