running-junit-tests-in-parallel

I’m using JUnit 4.4 and Maven and I have a large number of long-running integration tests.

When it comes to parallelizing test suites there are a few solutions that allow me to run each test method in a single test-class in parallel. But all of these require that I change the tests in one way or another.

I really think it would be a much cleaner solution to run X different test classes in X threads in parallel. I have hundreds of tests so I don’t really care about threading individual test-classes.

I opted for Junit-toolbox JUnit-Tool-Box

1. add this dependency to your POM.xml.

<dependency>
    <groupId>com.googlecode.junit-toolbox</groupId>
    <artifactId>junit-toolbox</artifactId>
    <version>1.5</version>
</dependency>

2. Write a Junit test classes.

package com.numerify.qa.tests.detailedtests;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.googlecode.junittoolbox.ParallelRunner;

@RunWith(ParallelRunner.class)
public class ParallelClassTest {
	@Before
	public void setup() {

	}

	@Test
	public void test1() {
		// TODO Auto-generated method stub
	}

	@Test
	public void test2() {
		// TODO Auto-generated method stub
	}

	@Test
	public void test3() {
		// TODO Auto-generated method stub
	}

	@After
	public void tearDown() {

	}
}

ParallelRunner — Executes all @Test methods as well as the calls to @Theory methods with different parameter assignments concurrently using several worker threads.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s