Speed up JUnit tests in Ant

reloading : a feature that passed me by

I've been having a few problems with some JUnit tests recently. They would run fine through IDEA, but would cause the JVM to hang whenever they were executed through an Ant build script. As a workaround, I just used the fork property of the junit task so that the tests would run in a separate JVM. This did the trick but slowed test execution down substantially.

In trying to solve this, I bought up the current documentation for the junit task and saw that v1.6 introduced a new reloading property. By default, the junit task creates a new classloader for each test case and this new property allows you to configure this behaviour. Now my tests work again and they're much, much faster. A handy little feature that passed me by.

Tags :


Re: Speed up JUnit tests in Ant

I'd rather user fork together with forkMode="once", that way you can be sure there is no interaction between Ant's classloader and your code - execution speed should be almost the same.

Re: Speed up JUnit tests in Ant

That's a good point, although the JVM still hangs with the fork mode set to "once". I can't even send a SIGQUIT to get a stack dump out. Something's not quite right somewhere, but turning off reloading fixes/works around the problem and speeds up test execution.

Re: Speed up JUnit tests in Ant

Sorry, I was getting mixed up with another configuration I was testing. You're right, forking only once also does the trick.

Add a comment Send a TrackBack