Reputation: 3757
Q&A-Style question as the existing questions don't match the simple typo I made here:
Goal
Problem
Code
import org.junit.jupiter.api.Test;
public class Test {
@Test
private void testAMethod() { (...) }
}
Upvotes: 7
Views: 17144
Reputation: 31
I know it is not relevant but if someone else is facing issue like me and none of the above solution works for you then check your target folder does it have classes files in this. I was having this same issue then I checked my target/classes folder and found it empty. Then I build my mvn again using mvn clean install and then it work like charm. when build was success but class file was not generated as I was using DskipTests
Upvotes: 1
Reputation: 301
Another possibility of this error message is when using a non-void return type. Switch to void and it will work.
Upvotes: 3
Reputation: 8467
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.
Upvotes: -7
Reputation: 2025
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/
Upvotes: 18
Reputation: 3757
The issue was a simply typo - the test was not visible from outside:
@Test
// Before
private void testAMethod() { (...)
// After
void testAMethod() { (...)
Upvotes: 1