How to run junit suite in parallel using maven surefire plugin

时光毁灭记忆、已成空白 提交于 2019-12-10 00:08:34

问题


I have a testsuite say JunitTest1 and JunitTest2 as below,

@RunWith(Suite.class)
@SuiteClasses({ 
    com.sample.test1.class,
    com.sample.test2.class,
    com.sample.test3.class,
})

public class JunitTest1 {

}

@RunWith(Suite.class)
    @SuiteClasses({ 
        com.sample.xxx1.class,
        com.sample.xxx2.class,
        com.sample.xxx3.class,
    })

    public class JunitTest2 {

    }

I want to run both the testsuite in parallel but the test class inside the testsuite should run in the specified order. I have added the below plugin in maven pom.xml,

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20.1</version>
                <configuration>
                    <parallel>suites</parallel>
                    <threadCount>2</threadCount>
                    <!-- <forkCount>1</forkCount>
                    <reuseForks>true</reuseForks> -->
                </configuration>
            </plugin>

I have followed this link - http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html

I have tried all the possible combination for parallel tag like methods, classes, both, suites, suitesAndClasses, suitesAndMethods, classesAndMethods, all but nothing seems to solve my problem. The test suite are still running in sequential if i use suites and for other options the test classes in test suite are running in random order

Is there anything i am doing it wrong? can anyone please guide me to solve this issue ?


回答1:


junit tests should be independent of one-another. junit does not provide a means to order tests to prevent you from writing tests which are dependent on other tests.

There are other SO threads on this topic:

How to run test methods in order with Junit

and

http://stackoverflow.com/questions/3693626/how-to-run-test-methods-in-specific-order-in-junit4



来源:https://stackoverflow.com/questions/47777892/how-to-run-junit-suite-in-parallel-using-maven-surefire-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!