【问题标题】:Why is maven-surefire-plugin compulsory when using JUnit 5 in a Maven project?为什么在 Maven 项目中使用 JUnit 5 时必须使用 maven-surefire-plugin?
【发布时间】:2017-08-11 07:40:27
【问题描述】:

我在没有maven-surefire-pluginmaven项目中使用JUnit 3和4很长时间了。

目前我开始尝试使用 JUnit Jupiter 包 org.junit.jupiter.api 中的注释来尝试 JUnit 5。特别是org.junit.jupiter.api.Test 被用来代替旧的org.junit.Test。最终,没有检测到任何测试,因此测试失败。

maven-surefire-plugin 必须添加到 pom.xml,如下所示: ```

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

<build>
  <plugins>
    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>${junit.platform.version}</version>
                </dependency>
        </dependencies>
    </plugin>
  </plugins>
</build>

所以我想问一下:

  • 为什么在 JUnit5 中必须使用 maven-surefire-plugin 而不是 JUnit4 或 JUnit3?
  • 是否有在没有maven-surefire-plugin 的情况下使用 JUnit 5 的解决方法?

让代码尽可能简单是我的习惯

【问题讨论】:

  • 我的假设是你使用了 maven-surefire-plugin 但没有明确定义它......现在你已经明确定义了它......除此之外 maven-surefire-plugin 中的包含配置不是必要的,因为它是默认的...目前在 maven-surefire-plugin 中对 JUnit5 的支持还没有完成....
  • @khmarbaise 感谢您对默认配置的评论 :) 我尝试根据您的评论删除 configuration 元素,但它仍然有效。所以关键是maven-surefire-plugin里面的dependencies
  • @khmarbaise 但我仍然想等待获得更全面的答案:)
  • 正如我所说,maven-surefire-plugin 中的 Junit5 支持尚未完成,需要一个新版本的 maven-surefire-plugin,目前正在开发中......请参阅 maven 开发列表。 ..
  • @khmarbaise 如果是这样,您可以为您的问题添加正式答案,我会投票正确。然后你会获得一些积分作为奖励:)

标签: maven junit junit5


【解决方案1】:

maven-surefire-plugin 中的 Junit5 支持尚未完成,需要一个新版本的 maven-surefire-plugin,即 currently being worked on

【讨论】:

    猜你喜欢
    • 2022-01-14
    • 1970-01-01
    • 2018-10-15
    • 2010-11-16
    • 1970-01-01
    • 2020-11-04
    • 1970-01-01
    • 2012-02-11
    • 2018-09-02
    相关资源
    最近更新 更多