Maven Surefire: Unable to fork parallel test execution

会有一股神秘感。 提交于 2019-12-05 03:42:58

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>

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.

Make sure you get a log message something like this

[INFO] Concurrency config is {perCoreThreadCount=false, threadCount=1, parallel=classes, configurableParallelComputerPresent=true}

Just before this heading:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

This message indicates that the parallel surefire junit provider is active.

If this is not present surefire may be picking up a different version of junit than you think. Anything below 4.7 will not work. Run mvn dependency:tree to check which version(s) are present.

You should also upgrade to surefire 2.6 since a number of minor bugs related to parallel running have been fixed. For the same reason you should use the latest junit.

Surefire's parallel mode is extremely buggy. For example, see http://jira.codehaus.org/browse/SUREFIRE-747 and http://jira.codehaus.org/browse/SUREFIRE-730

I haven't managed to get a single test running in parallel to date (not to mention forking).

Try changing your forkMode from always to "never". It does not state this in their documentation, but you can not have fork plus parallel at this time (we found this after digging through the surefire code.)

Just so you know, you will probably run into tests that are not thread safe due to many test/supporting libraries (easymock, powermock, etc) invalidating the ability to parallel your tests.

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.

Isn't parallel setting a TestNG only attribute? according to this: http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#parallel

The surefire 2.16 fixed the parallel execution regarding the JUnit tests.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!