ant-user mailing list archives

Re: The AntClassLoader created in one JUnitTask can not be used in another.

Date

Thu, 10 May 2007 11:05:22 GMT

Xu Xin wrote:
> Hello everyone,
>
> I had a problem with JUnitTask, I have a couple of xml files where I also
> have a lot of targets which contain <junit> tasks, originally I used the
> Apache Ant's JUnitTask, but unfortunately the test run had performance
> issue, that was caused by each <test> has its own classloader, as a result
> some static memory was created multiple times.
>
> So I customized the JUnitTask by making the classloader created for each
> test cacheable, the <junit> task has the same customer classpath elements
> share the same classloader, so I can save the memory as I can, but the
> strange thing is junit testcase was not recognized, it seemed a
> classloading issue, but after I ran the tests in DEBUG mode, I can find the
> classloader hierarchy is correct, I do not know what's going wrong. The
> snippet code is below:
>
>
>
> and next pass the classLoader to JUnitTestRunner as usual, the test class
> can be loaded, as well as JUnit class: TestSuite and Test, but when
> constructing TestCase, TestSuite complains the test class is not
> implementation of Test, but I can see the test class was loaded by cached
> AntClassLoader, and TestSuite and Test were loaded by its parent
> classloader. So could you guys please tell me what's wrong?
> Thanks
My recommendation would be to avoid these things; its very easy to leak
classes by sharing a classloader.
Just fork the junit run with fork="once" in your <junit> task
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org