【问题标题】:After updating to latest Spring boot version, spring-boot-starter-parent 2.6.2, my tests stop executing更新到最新的 Spring Boot 版本 spring-boot-starter-parent 2.6.2 后,我的测试停止执行
【发布时间】:2023-03-12 10:11:01
【问题描述】:

我已将 Spring boot 版本从 2.3.12.RELEASE 更新为 2.6.2 以包含 log4j 更改。现在,当我执行 mvn clean install 来构建我的代码时,它只执行一个单元测试。我有一个包含大约 423 个测试的测试套件,这些测试都在 2.3.12.RELEASE 中执行和通过。但现在即使是测试也不能正常执行。我没有看到任何此类事件的报告,所以我报告了一个。

我正在使用 PowerMockRunner 执行我的测试

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.2</version>
    <type>pom</type>
</dependency>

PowerMock dependencies

<dependency>
   <groupId>org.powermock</groupId>
   <artifactId>powermock-module-junit4</artifactId>
   <version>2.0.0</version>
   <scope>test</scope>
</dependency>
<dependency>
   <groupId>org.powermock</groupId>
   <artifactId>powermock-api-mockito2</artifactId>
   <version>2.0.0</version>
   <scope>test</scope>
</dependency>

【问题讨论】:

    标签: java spring spring-boot log4j


    【解决方案1】:

    从 Springboot 2.4 开始,他们删除了 JUnit4。如果您使用的是 JUnit4,则需要在 pom 中添加此依赖项:

    <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.hamcrest</groupId>
                    <artifactId>hamcrest-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    

    【讨论】:

    • 虽然在添加了这个依赖之后,测试类的执行开始了……但是其中有几个失败了。有什么解决办法吗?
    • 我在切换到 sb 2.4 时遇到了同样的问题,并补充说该依赖关系为我解决了。我还删除了 test.mv.db 和 test.trace.db,也许应该有所帮助。
    【解决方案2】:

    你使用的是什么版本的maven,你有没有使用junit maven插件。

    【讨论】:

    • org.powermockpowermock-module-junit42.0.0testorg.powermockpowermock-api-mockito22.0.0test依赖>
    • 这不是答案,而是评论。
    猜你喜欢
    • 2018-12-15
    • 2018-12-10
    • 2021-07-08
    • 2019-12-26
    • 1970-01-01
    • 2020-12-07
    • 2022-07-30
    • 2021-01-12
    • 2019-05-19
    相关资源
    最近更新 更多