Tuesday, February 27, 2007

[quick tips] To Speedup your junit testing in Ant

If your development project get bigger, and have incorporated thousands of test cases, u may find that unit testing target getting slower and slower. It may come to a point your developers start to ignore test cases, or worst, don't write any test cases at all, as it will slow down build process.

Now, before u look into your unit testing code to improve the performance, why don't have a check on your Ant Junit Target (I discovered this accidentally yesterday, as I am frustrated by the slow build process). If u have setup ur Ant to fork a new JVM for unit testing target, by default, Ant will fork a new VM per Test Class, which is slow, and expansive (imagine forking 1000+ jvm for your project). To correct this, we just needs to set correct forkmode="perBatch".
i.e
junit fork="true" forkmode="perBatch"

My test result, before forkmode="perBatch", my test process take ~= 16 minutes
after, my test process take < 2 minutes

Cheers, and happy coding

3 comments:

Anonymous said...

Woot! This shaved our test cases from 3hrs to 30 minutes. Thanks!

Thierry said...

Hay James, thanks a lot this reduced dramatically our test time too. Cheers. Thierry From UK.

Anonymous said...

I am trying to do the same, but then while the tests are being run, only the first test is shown in the output like:
[junit] Running com.xxx.MyTest

When my forkmode was perTest, each test class had a line like that.

Any suggestions on how to get the detailed runtime logging back?