“No tests were found” with Junit 5 and IntelliJ

前提是你 提交于 2020-04-16 04:23:13

问题


Q&A-Style question as the existing questions don't match the simple typo I made here:

Goal

  • Execute simple JUnit tests via the IntelliJ IDE using the UI (right-click: run test)

Problem

  • IntelliJ tells that "no tests were found"

Code

import org.junit.jupiter.api.Test;

public class Test {
    @Test
    private void testAMethod() { (...) }
}


回答1:


change to

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

According to Junit5 document

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/




回答2:


The issue was a simply typo - the test was not visible from outside:

@Test
// Before
private void testAMethod() { (...) 
// After
void testAMethod() { (...) 



回答3:


Junit in IntelliJ won't work on Java 10 or above. Try downgrading the project SDK to Java 8 and the tests will work like a charm.



来源:https://stackoverflow.com/questions/59288305/no-tests-were-found-with-junit-5-and-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!