Maven Surefire:无法分叉并行测试执行
使用 Maven Surefire,我无法分叉并行测试执行。也就是说,我的每个测试用例都必须在单独的 JVM 中运行,因此需要分叉。此外,我希望我的测试用例并行运行。第一部分工作没有问题:我能够在自己的 JVM 中运行每个测试用例。然而,第二部分对我来说仍然是一个挑战。我还没有设法让测试用例并行执行。这是我的插件声明的样子:
<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>
我已经尝试了方法和类,但没有看到任何并行化。 我的 JUnit 版本是 4.7,如依赖声明所示:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>compile</scope>
</dependency>
任何帮助将非常适用。
格雷瓜尔.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我认为你应该使用
threadCount使用
< 时的
参数代码>并行模式:I think that you are supposed to use the
threadCount
parameter when using theparallel
mode:我遇到了同样的问题,因为我使用的是 Surefire 版本 2.7,升级到 2.12 后它使用以下配置:
它生成了 4 个线程,每个线程运行它自己的 jvm。
I had the same problem, because i was using surefire version 2.7, after upgrade to 2.12 it worked with the following configuration:
It spawned 4 threads, each running it's own jvm.
确保您收到类似以下内容的日志消息
就在此标题之前:
此消息表明并行 Surefire junit 提供程序处于活动状态。
如果不存在,则可能会选择与您想象的不同版本的 junit。低于 4.7 的任何内容都不起作用。运行 mvn dependency:tree 以检查存在哪些版本。
您还应该升级到 Surefire 2.6,因为许多与并行运行相关的小错误已得到修复。出于同样的原因,您应该使用最新的 junit。
Make sure you get a log message something like this
Just before this heading:
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 的并行模式有很多错误。例如,请参阅 http://jira.codehaus.org/browse/SUREFIRE-747和 http://jira.codehaus.org/browse/SUREFIRE-730
我没有到目前为止,我们已经成功地并行运行了一个测试(更不用说分叉了)。
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).
尝试将 forkMode 从“始终”更改为“从不”。它没有在他们的文档中说明这一点,但是此时您不能使用 fork 加并行(我们在深入研究 Surefire 代码后发现了这一点。)
正如您所知,您可能会遇到由于以下原因而不是线程安全的测试:许多测试/支持库(easymock、powermock 等)使并行测试的能力失效。
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.
你确定它不起作用吗?如果您的测试不包含很多测试方法,您可能不会获得太多加速。使用 forkMode=always ,您能做的最好的事情就是并行运行类中的所有测试方法。
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.
并行设置不是只有 TestNG 属性吗?根据这个:
http://maven.apache.org/plugins/maven -surefire-plugin/test-mojo.html#parallel
Isn't parallel setting a TestNG only attribute? according to this:
http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#parallel
Surefire 2.16 修复了有关 JUnit 测试的并行执行。
The surefire 2.16 fixed the parallel execution regarding the JUnit tests.