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