本文介绍了如何使用Maven surefire插件并行运行junit套件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试套件,说如下的JunitTest1和JunitTest2,

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 {

    }

我想并行运行两个测试套件,但是测试套件中的测试类应按指定的顺序运行.我在maven pom.xml中添加了以下插件,

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>

我已点击此链接- http://maven .apache.org/surefire/maven-surefire-plugin/examples/junit.html

我已经尝试了所有并行标记的可能组合,例如方法,类,两者,套件,suitesAndClasses,suitesAndMethods,classesAndMethods,所有,但似乎没有什么能解决我的问题.如果我使用 suites ,则测试套件仍按顺序运行;对于其他选项,测试套件中的测试类按随机顺序运行

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 ?

推荐答案

junit测试应该彼此独立. junit没有提供订购测试的方法,以防止您编写依赖于其他测试的测试.

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.

关于此主题还有其他SO线程:

There are other SO threads on this topic:

如何与Junit一起按顺序运行测试方法

http://stackoverflow.com/questions /3693626/如何在Junit4中按特定顺序测试方法

这篇关于如何使用Maven surefire插件并行运行junit套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 05:12