我已经看到了很多关于与maven surefire并行运行JUnit测试的主题,但是我没有看到处理这个特定问题的答案.
简而言之:测试方法是并行执行的(好消息),但是道具不能限制我的线程.最终目标是并行化我的Web驱动程序和appium运行,但我希望能够首先控制总可能的线程.
下面的代码片段来自虚拟项目,仅用于演示.在apache文档之后,它看起来并不比下面的内容更多.
的pom.xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<parallel>methods</parallel>
<threadCountMethods>2</threadCountMethods>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
ExampleTest.class
public class ExampleTest {
@Test
public void one() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void two() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void three() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void four() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void five() …
Run Code Online (Sandbox Code Playgroud)