Maven Surefire: Unable to fork parallel test execu

2019-04-24 02:01发布

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.

8条回答
唯我独甜
2楼-- · 2019-04-24 02:30

Are you sure it's not working? You may not gain much speedup if your tests do not contain many test methods. With forkMode=always the best you can do is run all test methods within a class, in parallel.

查看更多
家丑人穷心不美
3楼-- · 2019-04-24 02:36

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.

查看更多
登录 后发表回答