【问题标题】:Junit (4.12) is not executing after spring-boot 2.6.2 migration在 spring-boot 2.6.2 迁移之后 Junit (4.12) 没有执行
【发布时间】:2022-01-28 10:23:25
【问题描述】:

我已经从 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

【问题讨论】:

标签: java spring spring-boot junit junit4


【解决方案1】:

我认为您应该迁移到 JUnit 5。

【讨论】:

    【解决方案2】:

    从 spring-boot-starter-test 依赖项中排除 junit-jupiter-engine 和 junit-vintage-engine,然后在你的 pom 中添加 JUnit 4 依赖项:

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

    【讨论】:

    • 这对我有帮助。你能解释一下吗?
    猜你喜欢
    • 1970-01-01
    • 2023-01-20
    • 2016-02-18
    • 2018-07-29
    • 2018-08-29
    • 2018-12-19
    • 2023-03-12
    • 1970-01-01
    • 2021-06-19
    相关资源
    最近更新 更多