问题描述
是否可以告诉Maven2在新的JVM实例(分支)中以串行方式(即,一个接一个地)执行每个jUnit测试.
Is it possible to tell Maven2 to execute every jUnit test in new JVM instance (fork) in serial mode, i.e. one by one.
推荐答案
您必须像解释的
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<forkMode>always</forkMode>
</configuration>
</plugin>
通过声明Sytem属性也应该有可能
It should also be possible by just declaring a Sytem property
mvn -DforkMode=always test
如文档中所述:始终"派生每个测试类.我不知道" pertest "设置是否会为每个测试派生.
As described in the documentation: "always" forks for each test-class. I do not know if the "pertest" setting will fork for each test.
感谢@Djebel指出现在已弃用forkMode
.有关" Fork选项和并行测试"的详细文档执行"以及如何使用新参数 forkCount
和 reuseForks
,其中还包括以下迁移提示:
Thanks to @Djebel for pointing out that forkMode
is deprecated now. There is a detailed documentation on "Fork Options and Parallel Test Execution" and how to use the new parameters forkCount
and reuseForks
and that also includes the following migration tips:
Old Setting New Setting
forkMode=once (default) forkCount=1 (default), reuseForks=true (default)
forkMode=always forkCount=1 (default), reuseForks=false
forkMode=never forkCount=0
forkMode=perthread, threadCount=N forkCount=N, (reuseForks=false, if you did not had that one set)
这篇关于如何告诉Maven2在新的JVM实例中一个接一个地执行jUnit测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!