Unstable Terrain

Software development in the real world

Ant Junit task Addendum: forkmode

leave a comment »

I mentioned previously about using the ant junit task with fork=false.

However, some tools such as EMMA insert shutdown hooks, so require forking. In addition, classloader issues may require you to fork to save your own sanity.

Turns out there’s a more robust solution.

<junit  haltonfailure="yes"
    <classpath refid="test.class.path.with.test.classes" />
    <formatter type="xml" />
    <batchtest toDir="${test.reports}">
        <fileset dir="${test.classes.dir}">
            <include name="**/*Test*.class" />

A new JVM will be forked, but all tests will be run inside that single forked JVM, increasing the speed of your tests substantially. If you have some tests that have side-effects, you can put them into a separate batch and change the forkmode to ‘perBatch‘, effectively isolating them while retaining the speed of the rest of your tests.

So, try it and see how much faster your build goes.


Written by Trent

July 26, 2010 at 6:44 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: