当前位置: 首页 > 知识库问答 >
问题:

与surefire和testng并行运行测试

翁翰墨
2023-03-14

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

我的意图是并行运行所有测试(直到方法级别)。那么,我该如何实现呢?

共有1个答案

怀宇
2023-03-14

我不认为所有都是TestNG的选项。尝试使用

 类似资料:
  • 我试图用TestNG并行运行一个示例测试项目。但它是在一个线程中顺序执行的。我漏掉什么了吗? 谢了。

  • 它是可以配置surefire插件只运行一些测试并行和其他顺序? 也可以使用surefireforkCount来运行声明为jUnit Suite的并行测试吗?

  • 共设5个测试班。每一个都使用@Factory(dataprovider=“data”)初始化。我想实现的是,每个测试类中的测试方法应该与dataprovider实例并行运行。此外,测试类应该并行运行。 如下所示。TestClass1应该并行运行dataprovider实例。因此,测试类TestClass1的所有方法将为dataprovider实例并行运行。 data-provider-thread

  • 如果我使用,如下所示: 然后,当测试执行第一次开始时,所有的web驱动程序都填满了,但是它很快就开始删除并一次执行一个驱动程序。 所以我的问题是: null

  • 这是驱动程序类,它将为每个测试方法创建驱动程序实例。