如何使用Maven Failsafe插件运行JUnit 5集成测试? [英] How do I run JUnit 5 integration tests with the Maven Failsafe plugin?

查看:142
本文介绍了如何使用Maven Failsafe插件运行JUnit 5集成测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行命令mvn clean failsafe:integration-test时,Maven Failsafe插件找不到我的JUnit 5集成测试,尽管它可以找到文件.

The Maven Failsafe plugin won't find my JUnit 5 integration tests when I'm running the command mvn clean failsafe:integration-test, although it can find the files.

我将junit-jupiter-apijunit-jupiter-engine作为测试依赖项:

I have the junit-jupiter-api and junit-jupiter-engine as test dependencies:

<properties>
    <junit.jupiter.version>5.0.1</junit.jupiter.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

我的集成测试的名称正确(在**/*IT.java**/IT*.java**/*ITCase.java之前,它们由Failsafe缺省包含,而由Surefire缺省排除).

My integration tests are named correctly (following the **/*IT.java, **/IT*.java, or the **/*ITCase.java that included by default by Failsafe and excluded by default by Surefire).

我可以通过Failsafe使用JUnit 5测试吗?

Is there any way that I can use JUnit 5 tests with Failsafe?

推荐答案

请注意,来自

Note that from the JUnit 5 documentation : junit-platform-surefire-provider should be not used any longer :

由于Surefire 2.22.0的发布, JUnit团队的junit-platform-surefire-provider 已过时,并将在以后的版本中停止使用 JUnit平台.

Due to the release of Surefire 2.22.0, the junit-platform-surefire-provider from the JUnit team has been deprecated and will be discontinued in a subsequent release of the JUnit Platform.

此外,您还可以阅读 文档:

使用JUnit 5平台

要开始使用JUnit Platform,您至少需要添加一个 TestEngine实施到您的项目.例如,如果您想 用Jupiter编写测试,添加测试工件junit-jupiter-engine 到POM中的依赖项

To get started with JUnit Platform, you need to add at least a single TestEngine implementation to your project. For example, if you want to write tests with Jupiter, add the test artifact junit-jupiter-engine to the dependencies in POM

所以您必须指定此test依赖项:

So you have to specify this test dependency :

<properties>
    <junit-jupiter.version>5.2.0</junit-jupiter.version>
</properties> 

<dependencies>
     [...]
     <dependency>
         <groupId>org.junit.jupiter</groupId>
         <artifactId>junit-jupiter-engine</artifactId>
         <version>${junit-jupiter.version}</version>
         <scope>test</scope>
     </dependency>
     [...] 
</dependencies>

maven-failsafe-plugin声明可以很简单:

<build>
    <plugins>           
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.22.0</version>
        </plugin>
    </plugins>
</build>  

这篇关于如何使用Maven Failsafe插件运行JUnit 5集成测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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