无法使用Maven执行Junit5测试

时间:2016-12-20 04:25:15

标签: java maven unit-testing 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 is not picking up Junit 5 tests的解决方案,将依赖关系更新为 -

<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下正常运行。

1 个答案:

答案 0 :(得分:3)

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

pillow

您只需要包含junit-jupiter-api工件,并且只能包含在依赖项部分的测试范围中:

<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>

有关详细信息,请参阅this

编辑 - 来自相同的文档。

  

为了让Maven Surefire运行任何测试,<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.0.0-M3</version> <scope>test</scope> </dependency>   必须将实现添加到运行时类路径中。

TestEngine
相关问题