intellij-idea - "No tests were found"使用 Junit 5 和 IntelliJ

标签 intellij-idea junit

问答式问题,因为现有问题与我在此处输入的简单错字不符:

目标

  • 使用 UI 通过 IntelliJ IDE 执行简单的 JUnit 测试(右键单击:运行测试)

  • 问题
  • IntelliJ 说“没有找到测试”

  • 代码
    import org.junit.jupiter.api.Test;
    
    public class Test {
        @Test
        private void testAMethod() { (...) }
    }
    
    

    最佳答案

    改成

    public void testAMethod() { (...) }
    

    根据 Junit5 文档

    Test classes, test methods, and lifecycle methods are not required to be public, but they must not be private.



    https://junit.org/junit5/docs/current/user-guide/

    关于intellij-idea - "No tests were found"使用 Junit 5 和 IntelliJ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59288305/

    相关文章:

    intellij-idea - IntelliJ Idea groovy.lang.GroovyRuntimeException : Conflicting module versions

    c# - 反射是否打破了私有(private)方法的想法,因为私有(private)方法可以在类之外访问?

    java - 当与 JUnit 一起使用方法时,jdbcTemplate 为 null

    java - hibernate validator : Violation Message Language

    java - 在对 void 方法进行单元测试时,如何确定集合中的元素?

    java - 为不同的 JUnit 测试使用不同的类加载器?

    java - 在 IntelliJ 中导入 JsonFormat 时出现问题

    intellij-idea - 如何控制 Intellij Idea 14 - 索引和 VCS 刷新行为

    eclipse - 如何在 Intellij 中将两个选项卡合并为一个 float 窗口?

    java - Intellij Idea中添加外部库的一些问题