java - JUnit 4 测试结果未显示在 Eclipse 中

标签 java eclipse unit-testing junit junit4

我的问题是 JUnit 4 测试结果未在 Eclipse 中显示。 我已将 System.out.println("....") 添加到我的测试类中的每个 @Test 方法,并且它们运行导致控制台显示输出,但是,我的包资源管理器旁边的 JUnit 选项卡未显示任何结果。它显示运行 0/0、错误 0、失败 0。

我应该补充一点,我已经添加了 JUnit 4 来构建路径。 我浏览互联网寻找答案大约一个小时,但什么也没找到。这里有什么问题?我真的很感激任何线索!

最佳答案

我在使用Spring Boot 2.5.1时遇到了同样的问题

本质上,从 Spring Boot 2.4 开始,JUnit 5 的老式引擎已从 spring-boot-starter-test 中删除。如果我们仍然想使用 JUnit 4 编写测试,我们需要添加以下 Maven 依赖项:

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

关于java - JUnit 4 测试结果未显示在 Eclipse 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29738490/

相关文章:

java - 私有(private)方法真的安全吗?

java - Flyway脚本不使用Spring Boot执行

java - Vertx 单元测试永远不会完成

database - 测试 MS Access 应用程序的最佳方式?

asp.net-mvc - ASP.Net MVC 中 HttpContext 和可测试 Controller 的最佳实践

java - 如何强制 Java 线程关闭线程本地数据库连接

java - Java 中的 Longs 是否过于苛刻?为什么这样?

java - 32/64 位 eclipse

java - 无法解决 Eclipse "Archive for required library..."问题

android eclipse jedisct1/libsodium 从哪里开始