pap*_*y-o 4 junit4 parallel-testing maven-surefire-plugin
我已经看到了很多关于与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() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void six() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void seven() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void eight() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void nine() throws InterruptedException {
Thread.sleep(5000);
}
@Test
public void ten() throws InterruptedException {
Thread.sleep(5000);
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这个类的完整运行与提供的pom配置需要花费超过25秒(10次睡眠,持续5秒,每次运行两次).实际运行时间略大于5秒:
Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.022 sec - in ExampleTest
Run Code Online (Sandbox Code Playgroud)
更改threadCountMethods prop对运行时没有影响(看起来所有方法并行进行而不考虑threadCount prop).
任何投入将不胜感激; 谢谢!
| 归档时间: |
|
| 查看次数: |
697 次 |
| 最近记录: |