javaautomated-testspom.xmlsurefiretest-suite

Surefire run certain tests in sequence, others in parallel


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>

Solution

  • 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.