Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running junit tests in parallel in a Maven build?

Tags:

java

junit

maven

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.

Is there any way to do this?

like image 298
krosenvold Avatar asked Jan 08 '09 08:01

krosenvold


People also ask

Does Maven run JUnit tests in parallel?

Maven Dependencies In a nutshell, Surefire provides two ways of executing tests in parallel: Multithreading inside a single JVM process. Forking multiple JVM processes.

Can we do parallel testing in JUnit?

Yes, You can. Show activity on this post. JUnit Toolbox provides JUnit runners for parallel execution of tests.

Does surefire run tests in parallel?

The surefire offers a variety of options to execute tests in parallel, allowing you to make best use of the hardware at your disposal. But forking in particular can also help keeping the memory requirements low.


2 Answers

Use maven plugin:

<build>     <plugins>     <plugin>         <groupId>org.apache.maven.plugins</groupId>         <artifactId>maven-surefire-plugin</artifactId>         <version>2.7.1</version>         <configuration>             <parallel>classes</parallel>             <threadCount>5</threadCount>         </configuration>     </plugin>     </plugins> </build> 
like image 141
Oleksandr Avatar answered Sep 18 '22 09:09

Oleksandr


From junit 4.7 it's now possible to run tests in parallel without using TestNG. Actually it has been possible since 4.6, but there are a number of fixes being made in 4.7 that will make it a viable option. You may also run parallel tests with spring, which you can read about here

like image 20
krosenvold Avatar answered Sep 21 '22 09:09

krosenvold