首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用Maven执行Junit5测试

无法使用Maven执行Junit5测试
EN

Stack Overflow用户
提问于 2016-12-20 04:25:15
回答 1查看 1.6K关注 0票数 3

Maven执行

代码语言:javascript
复制
mvn clean test

我试图在我的maven项目中使用junit5,但无法在test阶段使用-

代码语言:javascript
复制
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.0.0-M3</version>
</dependency>

我得到的输出是-

信息-- maven-surefire-plugin:2.19.1:test (默认-test)@ utils -E、S-S失败: 0,错误: 0,跳过:0

尝试实现前面提到的解决方案@ Surefire is not picking up Junit 5 tests,以便将依赖项更新为-

代码语言:javascript
复制
<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>

并将插件更新为-

代码语言:javascript
复制
<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来执行测试?

Note -测试执行在JUnit-4中运行良好。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-20 07:11:40

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

代码语言:javascript
复制
<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工件:

代码语言:javascript
复制
<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完全运行任何测试,必须将TestEngine实现添加到运行时类路径中。

代码语言:javascript
复制
<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>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41234886

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档