无法使用Maven执行Junit5测试

纳曼

Maven执行

mvn clean test

我正在尝试将其junit5用于一个Maven项目,但在此test阶段无法使用-

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.0.0-M3</version>
</dependency>

我得到的输出是-

[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ utils ---

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

尝试实施上述解决方案@ Surefire没有采用Junit 5测试来将依赖关系更新为-

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.0.0-M3</version>
</dependency>
<dependency>
    <groupId>org.junit</groupId>
    <artifactId>junit5-api</artifactId>
    <version>5.0.0-ALPHA</version><!--https://mvnrepository.com/artifact/org.junit/junit5-api -->
    <scope>test</scope>
</dependency>

并将插件更新为-

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <dependencies>
        <dependency>
            <groupId>org.junit</groupId>
            <artifactId>surefire-junit5</artifactId>
            <version>5.0.0-ALPHA</version><!--couldn't find this on the central though-->
        </dependency>
    </dependencies>
</plugin>

但输出保持不变。

问题-这是自定义提供没有更多的支持,或者是有什么解决方案使用执行测试mavenjunit5和/或junit5-api现在?

注意-测试执行在JUnit-4上运行良好。

马克·菲利普

您应该像这样配置maven-surefire-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.0.0-M3</version>
        </dependency>
    </dependencies>
</plugin>

您仅需要包括junit-jupiter-api工件,并且仅在“依赖关系”部分的测试范围内即可:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.0.0-M3</version>
    <scope>test</scope>
</dependency>

有关更多信息,请参见http://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven

编辑-来自相同的文档。

为了使Maven Surefire完全运行任何测试,TestEngine必须在运行时类路径中添加一个实现。

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.0.0-M3</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.0.0-M3</version>
        </dependency>
    </dependencies>
</plugin>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Maven surefire插件无法检测Junit5测试

无法使用Spring Boot Gradle插件通过依赖项管理执行junit5测试

究竟选择哪个JUnit5标签使用Maven执行

Maven不会运行JUnit5测试

JUnit Jupiter(JUnit5)中的参数化测试执行

如何使用Maven AND JUnit5标签

使用JUnit5和Spring-boot-starter-parent时不执行任何测试

使用LiveData进行JUnit5测试不会执行订阅者的回调

为每个测试类执行 JUnit5 BeforeAllCallback

如何让android studio“gradlew test”执行junit5测试?

如何使用Maven运行作为插件安装到Eclipse应用程序的JUnit5测试

无法使用JUnit5控制台启动器运行测试

无法在Docker容器中使用Bazel运行JUnit5测试

使用junit5时,Springboot测试无法自动连接TestRestTemplate

尝试使用Maven运行Mockito junit5测试时,java.lang.NoClassDefFoundError:org / junit / platform / commons / PreconditionViolationException

使用 JUNIT5 测试用例处理多个异常

使用Junit5进行Gradle多项目集成测试

如何使用 JUnit5 在 OpenEJB 中测试 EJB Bean?

如何在JUnit5中为测试套件设置自定义测试执行顺序?

无法运行测试类“未找到测试运行程序‘Junit5’的测试”

使用Mockito和jUnit5的SpringBoot Controller测试失败,因为Spring无法创建可加载属性的PropertyService类的bean?

正确配置JUNIT5以进行测试

JUnit5:如何重复失败的测试?

测试中的JUnit5断言计数

注释记录Junit5中每个测试用例的执行时间

如何配置Maven插件以运行Spock和Junit5测试

在junit5上使用测试服测试多个类即将挂起

MapStruct无法通过Spring-boot测试Gradle Junit5自动工作

如何使用JUnit5为Kafka消息使用者测试PACT