Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Surefire: Unable to fork parallel test execution

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.

like image 719
Gregoire Avatar asked Aug 30 '10 11:08

Gregoire


People also ask

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.

How can you use Maven to run unit 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.

How do you run a test parallel without TestNG?

Run tests in parallel without a framework We show 3 such ways below but this is not an exhaustive list: Using a multi-threaded Java program (manually managing threads) Using a multi-threaded program and using an ExecutorService to manage threads. Writing a shell script to invoke multiple Java programs in parallel.

How can we run test cases in parallel using TestNG?

To trigger parallel test execution in TestNG, i.e., run tests on separate threads, we need to set the parallel attribute. This attribute accepts four values: methods – runs all methods with @Test annotation in parallel mode. tests – runs all test cases present inside <test> tag in the XML in parallel mode.


2 Answers

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>
like image 199
Pascal Thivent Avatar answered Sep 25 '22 05:09

Pascal Thivent


I had the same problem, because i was using surefire version 2.7, after upgrade to 2.12 it worked with the following configuration:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.12</version>
  <configuration>
    <parallel>classes</parallel>
    <forkMode>perthread</forkMode>
    <threadCount>4</threadCount>
  </configuration>
</plugin>

It spawned 4 threads, each running it's own jvm.

like image 21
Leo Gamas Avatar answered Sep 25 '22 05:09

Leo Gamas