gpt4 book ai didi

java - 在 spring-boot 2.6.2 迁移之后 Junit (4.12) 没有执行

转载 作者:行者123 更新时间:2023-12-05 00:51:54 25 4
gpt4 key购买 nike

我已经从 Spring 迁移到 Spring-boot 版本 2.6.2。 mvn clean install 成功,但没有一个junit(4.12版)正在执行。经过一些研究,我知道从 Spring-boot 2.4 开始,JUnit4 已被删除。我尝试了以下不起作用的解决方案。

After updating to latest Spring boot version, spring-boot-starter-parent 2.6.2, my tests stop executing

Spring Boot maven unit tests not being executed

最佳答案

JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage。

引用:Junit5 doc

如果你根据最新的 spring-boot-starter-test 导入 junit-jupiter,它只会运行 Junit5 风格的测试用例。所以 Junit 提供 junit-vintage 来运行旧的 Junit3/Junit4 案例,默认情况下它不包含在 spring-boot-starter-test 依赖项中。所以有两种解决方案可以让 Junit4 继续运行:

  1. 同时依赖 junit-jupiter 和 junit-vintage 来支持所有 Junit3/4/5 案例。

     <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <scope>test</scope>
    </dependency>
  2. 从 spring-boot-starter-test 中排除 junit-jupiter 以运行 Junit4

     <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
    <exclusion>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    </exclusion>
    </exclusions>
    </dependency>

关于java - 在 spring-boot 2.6.2 迁移之后 Junit (4.12) 没有执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70892138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com