ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jaikiran Pai <jai.forums2...@gmail.com>
Subject Re: ClassLoaders in JUnit Launcher Task
Date Sun, 03 Jun 2018 09:45:05 GMT

On 03/06/18 3:13 PM, Jaikiran Pai wrote:
> I have now added a section in the junitlauncher task's manual 

The section's titled "Using the classpath element to include test engines".

-Jaikiran

> to include an example which shows how to setup the classpath element 
> to include thetestengines. The document isn't live yet but can be 
> found in its raw form here[1].
>
> I'm not 100% sure if this is what you were after, so feel free to 
> reply with details if there's something else you are looking for.
>
> [1] 
> https://raw.githubusercontent.com/apache/ant/master/manual/Tasks/junitlauncher.html
>
> -Jaikiran
> On 02/06/18 8:39 AM, Jaikiran Pai wrote:
>> 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-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message