maven - 与 surefire 和 testng 并行运行测试

标签 maven testing testng parallel-testing

我正在试验如何与 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");
    }
}

这是我的万无一失的配置:

        <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>如果您希望所有测试用例并行执行。

关于maven - 与 surefire 和 testng 并行运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26368305/

相关文章:

java - 如何选择maven依赖项:list?的输出

ruby - 如何测试执行*大量*参数处理的方法?

c++ - C/C++ 测试框架(如 JUnit for java)

使用 Java 进行测试

java - TestNG 监听器的顺序 (java Webdriver)

java - 如何在 Maven 中排除特定的单元测试

java - Maven 编译失败 ("invalid target release")

java - 无法在 IntelliJ 中编译/运行 Java 项目

c++ - 随机数据测试

java - 如何创建类的公共(public)对象以在 TestNG 类的所有方法中使用?