在异步中运行mvn集成测试

时间:2017-01-19 14:26:04

标签: java maven

我在我的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 failsafe插件:

        <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

如何让它们运行异步?

1 个答案:

答案 0 :(得分:0)

根据docs从JUn​​it 4.7开始,您可以并行运行测试

确保将junit依赖关系设置为正确的版本

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.7</version>
    </dependency>