Speeding up tests in Ant

Posted by andy in : Agile, Software, Testing on September 21, 2005

I have always been frustrated at how slow ant is at running my tests.  If I run my tests in Intellij it takes around 4 minutes to run 1300 tests.  The same tests in ant take over 12 minutes.

This is not such a big deal when I’m developing as I run them all in Intellij.  The problem is that the Continuous Integration server runs ant.  If the automatic build takes too long following a commit, I will have started working on something else.

I was telling people this as a recent Agile Summer School that Duncan Pierce and I ran. Justin Forder did some digging around and found the magic forkmode attribute…

You normally fork a new JVM to run the tests since it isolates your tests from Ant’s environment (which places a lot of libraries on the classloader).  The reason it’s slow is that the default behavior is to fork a new JVM for each test case class.  That’s a lot of forking.

It turns out that Ant 1.6.2 introduced a new junit task attribute called “forkmode“. If you set it to “once“, Ant will fork a single Java VM for all your tests classes.

Fantastic, the build server is now running all the tests in 6 minutes (it’s not as fast as my development machine).

Thanks to Justin Forder for pointing this out to me.   See Stefan Bodewig’s Weblog for more info

Add to del.icio.us , Digg this ,

Leave a Reply

 

Site Map | design by twothirty