Parallelize your JUnit tests with the Test Load Balancer

One of Go's most valuable features is that it runs jobs in parallel. To make long running test suites go faster, you can simply split your long running test suite into multiple suites and create jobs for each one. Given enough build agents, Go can run all jobs within a specified stage simultaneously, which means your long running testing can be done in a snap.

But wait, why do I need to manually split my test suites? Enter the test load balancer.

For example, I have a unit-test target in my ant build script which includes more than 100 tests. Those tests are organized by corresponding packages, so it's hard to split them in an easy way. It's a burden to users of Go.

What is the test load balancer?

The TLB (test load balancer) is a custom ant task that can split test suites written in junit for you. With TLB, you can simply specify in Go how many batches you want to split your test suite into. TLB talks to Go to work out how many batches your suits is split into and which of these batches the current job should do. 

How do I use it?

First, download test load balancer jar file and add it to the classpath of ant build script.

Then, change your build.xml as following:

<typedef name="filter-fileset" classname="" classpathref="classpath"/>

<batchtest todir="target/test-results">
<filter-fileset dir="target/test-classes" includes="**/*Test.class"/>
<classpath refid="classpath" />

Third, change your Go configuration. You will need to create a job for each batch of tests you want to run. Go makes sure these jobs will run in parallel. You need to make each job run the same ant task - the one you put the typedef above into. But you use a naming convention so that the TLB can recognize them.

For example, say you have a unit test job running on Linux environment named 'ut-linux' that has 100 tests and takes 10 minutes. You want to split it to three batches. You simply replace the old 'ut-linux' job with three jobs: 'ut-linux-1', 'ut-linux-2', 'ut-linux-3'. Each job should do exactly the same thing as the original ut-linux job.

That's it - you're done! Now you can get the benefits of faster, parallelized test running with no changes to your junit test suite.

Further information about the test load balancer.