Maven Surefire: Unable to fork parallel test execution

Gregoire picture Gregoire · Aug 30, 2010 · Viewed 8.6k times · Source

using Maven surefire, I'm unable to fork parallel test execution. That is, each of my test cases hs to run in a serapate JVM, hence the forking. In addition, I want my test cases to run in parallel. the first part is working without problem: I'm able to run each test case in its own JVM. the second part, however is still a challene for me. I haven't managed to get the paralle execution of test cases working. Here is how my plugin declaration look like:

    <plugin>
          <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.5</version>
      <configuration>
           <parallel>methods</parallel>
           <forkMode>always</forkMode>
                <argLine>-Xms512m -Xmx512m</argLine>
       </configuration>
</plugin>

I've tried both methods and classes but haven't see any parallelization. My JUnit version is 4.7 as shown by the depency declaration:

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.7</version>
        <scope>compile</scope>
    </dependency>            

Any help would be much appricated.

Gregoire.

Answer

Pascal Thivent picture Pascal Thivent · Aug 31, 2010

I think that you are supposed to use the threadCount parameter when using the parallel mode:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.6</version>
    <configuration>
      <forkMode>always</forkMode>
      <argLine>-Xms512m -Xmx512m</argLine>
      <parallel>methods</parallel>
      <threadCount>4</threadCount>
    </configuration>
  </plugin>