[英]Run tests in parallel with surefire and testng
我正在嘗試如何與Maven surefire和testng並行運行測試。 但是,配置似乎不是很簡單,我無法使其正常工作。 以下是我的虛擬測試。
@Log4j
public class DummyTest {
@Test
public void test_1() throws InterruptedException {
log.info("test 1 started");
Thread.sleep( 3000 );
assertTrue(true);
log.info("test 1 ended");
}
@Test
public void test_2() throws InterruptedException {
log.info("test 2 started");
Thread.sleep( 5000 );
assertTrue(true);
log.info("test 2 ended");
}
}
//------------------------------------
public class Dummy2Test {
@Test
public void test_1() throws InterruptedException {
log.info("test 1 started");
Thread.sleep( 3000 );
assertTrue(true);
log.info("test 1 ended");
}
@Test
public void test_2() throws InterruptedException {
log.info("test 2 started");
Thread.sleep( 5000 );
assertTrue(true);
log.info("test 2 ended");
}
}
這是我的surefire配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<parallel>all</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>
這些測試實際上是按順序運行的。 以下是日志作為證據:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.tns.ct.tests.Dummy2Test
Configuring TestNG with: TestNG652Configurator
2014-10-14 18:51:18 INFO com.tns.ct.tests.Dummy2Test.test_1():12 - test 1 started
2014-10-14 18:51:21 INFO com.tns.ct.tests.Dummy2Test.test_1():15 - test 1 ended
2014-10-14 18:51:21 INFO com.tns.ct.tests.Dummy2Test.test_2():20 - test 2 started
2014-10-14 18:51:26 INFO com.tns.ct.tests.Dummy2Test.test_2():23 - test 2 ended
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.316 sec - in com.tns.ct.tests.Dummy2Test
Running com.tns.ct.tests.DummyTest
Configuring TestNG with: TestNG652Configurator
2014-10-14 18:51:27 INFO com.tns.ct.tests.DummyTest.test_1():12 - test 1 started
2014-10-14 18:51:30 INFO com.tns.ct.tests.DummyTest.test_1():15 - test 1 ended
2014-10-14 18:51:30 INFO com.tns.ct.tests.DummyTest.test_2():20 - test 2 started
2014-10-14 18:51:35 INFO com.tns.ct.tests.DummyTest.test_2():23 - test 2 ended
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.318 sec - in com.tns.ct.tests.DummyTest
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
我的意圖是並行運行所有測試(直至方法級別)。 那么,我該如何實現呢?
我認為TestNG並不是全部。 如果希望所有測試用例都並行執行,請嘗試使用<parallel>methods<\\paralell>
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.