Is there a way to make certain tests run in in sequence with the surefire plugin for JUnit? Currently it is running all tests in parallel, but some tests are very hard to convert and it would be sufficient if they didn't run in parallel. Here is a part of our pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.17</version>
</dependency>
</dependencies>
<configuration>
<parallel>all</parallel>
<threadCount>8</threadCount>
<includes>
<include>${includeTest}</include>
<include>${includeAdditionalTest}</include>
</includes>
</configuration>
</plugin>
Consult the surefire plugin documentation. It provides a way to specify that certain tests are not thread safe by using @NotThreadSafe
annotation.
Another solution is to specify two separate surefire executions with explicit test inclusions and exclusions. One execution could run in parallel mode including the thread safe suites, the other those non thread safe.
We can achieve by defining multiple executions
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>unit-test</id>
<phase>unit-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<parallel>methods</parallel>
<threadCount>4</threadCount>
<perCoreThreadCount>true</perCoreThreadCount>
<excludes>
<!-- run all UTs (non-ITs) parallel -->
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<!-- run integration tests sequentially -->
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With