Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven 与surefire和testng并行运行测试_Maven_Testing_Testng_Parallel Testing - Fatal编程技术网

Maven 与surefire和testng并行运行测试

Maven 与surefire和testng并行运行测试,maven,testing,testng,parallel-testing,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(t

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

我的意图是并行运行所有测试到方法级别。那么,我如何才能做到这一点呢?

我不认为一切都是TestNG的选项。如果希望所有测试用例并行执行,请尝试使用方法。

我试过了。不幸的是,它工作得不是很好。无论如何,我已经通过使用testng.xml解决了我的问题,在这里我指定了并行策略?我确实尝试了示例代码,它在不包含testng.xml文件的情况下运行良好。我能够并行运行测试方法。我尝试了surefire 2.21.0版本和testng 6.8.21
-------------------------------------------------------
 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