[英]run mvn integration tests in async
我正在Java應用程序上運行集成測試。
這是我的代碼:
public class MyClassIT {
@Before
public void setUp() throws Exception {
setUp();
}
@Test
public void test1() throws Exception {
doTheIntegration(1);
}
@Test
public void test2() throws Exception {
doTheIntegration(2);
}
@Test
public void test3() throws Exception {
doTheIntegration(3);
}
private static void doTheIntegration(int i) {
System.out.println("started--" + i);
doSomethingLongerThan1Minute();
System.out.println("done--" + i);
}
@After
public void tearDown() throws Exception {
tearDown();
}
}
這是pom故障安全插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<parallel>methods</parallel>
<threadCount>10</threadCount>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
我正在運行mvn verify
並期望所有3個測試都異步發生,但它們正在同步運行
$ mvn verify
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.example.MyClassIT
started--1
done--1
started--2
done--2
started--3
done--3
如何使它們異步運行?
根據文檔,從JUnit 4.7起,您可以並行運行測試
確保將junit依賴項設置為正確的版本
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
</dependency>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.