使用maven-failsafe-plugin在Maven中运行JUnit4测试套件 [英] Running a JUnit4 Test Suite in Maven using maven-failsafe-plugin

查看:227
本文介绍了使用maven-failsafe-plugin在Maven中运行JUnit4测试套件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JUnit 4测试套件,其中包含许多测试类,这些类按它们需要运行的顺序进行(我们的Integration测试需要按一定的顺序运行).

I've got a JUnit 4 test suite that contains a number of test classes in the order they need to be run (our Integration tests need to be run in a certain order).

如果我使用不带任何配置的maven-failsafe-plugin,它将运行测试,但顺序不正确.但是,如果我将插件设置为运行测试套件,则不会运行任何测试.

If I use the maven-failsafe-plugin without any configuration it will run the test but not in the correct order. However, If I set the plugin to run the test suite no tests are run.

是否可以使用故障安全插件运行测试套件?如果是这样,我哪里出错了!

Is it possible to run a test suite using the failsafe plugin? if so, where have I gone wrong!!

代码如下:

@RunWith(Suite.class)
@SuiteClasses({ 
    TestCase1.class,
    TestCase2.class, 
       ...
    TestCaseN.class,
})
public class IntegrationSuite {
    //Do Nothing.
}

并来自pom.xml:

and from pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.9</version>
    <configuration>
        <includes>
            <include>IntegrationSuite.java</include>
        </includes>
    </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>

谢谢:)

推荐答案

故障保护插件支持

Failsafe plugin supports runOrder (click) parameter since version 2.7 (quite recent). There aren't many options, you cannot specify the order explicitly, but you can set it to "alphabetical" and rename your test classes to reflect the run order.

我还可以说测试相互依赖的事实是(测试)代码气味;这不是很好,因为这是开发一套无法维护的测试并最终在其复杂性飞涨至人类无法理解时最终放弃它的一条捷径.另外,由于它是一个选定的执行路径的结果,因此可能无法暴露错误.

May I also say on the occasion that the fact that test depend on each other is (test) code smell; it's not good, as it is a short path to developing an unmaintainable set of tests and abandoning it finally when its complexity skyrockets above human comprehension. Plus it may fail to expose bugs, as it is a result of one chosen execution path.

顺便说一句,我更喜欢这样的测试,并带有双星号:

BTW, I prefer to include tests like this, with a double asterisk:

<includes>
     <include>**/IntegrationSuite.java</include>
</includes>

这篇关于使用maven-failsafe-plugin在Maven中运行JUnit4测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆