问题描述
是否可以告诉 Maven2 以串行模式在新的 JVM 实例(fork)中执行每个 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.
推荐答案
你必须像解释的那样 fork JVM 这里
You have to fork the JVM like explained here
<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 Options and Parallel Test的详细文档执行"以及如何使用新参数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测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!