JUnit "No runnable methods" empty test class in CI
The runner loaded a test class but found no methods it considers tests. This is almost always a JUnit version mix-up: the class uses the JUnit 4 @Test while the runner expects JUnit 5 (or vice versa), so the annotations are not recognized.
What this error means
The build fails with "java.lang.Exception: No runnable methods" for a class that clearly has test methods. It often appears after migrating to JUnit 5 without the vintage engine or with the wrong @Test import.
initializationError(com.acme.UserServiceTest)
java.lang.Exception: No runnable methods
at java.base/jdk.internal.reflect...Common causes
Wrong @Test import for the engine
The class imports org.junit.Test (JUnit 4) but runs under JUnit 5 (org.junit.jupiter.api.Test), so Jupiter sees no test methods.
No vintage engine for JUnit 4 tests
A JUnit 5 platform without junit-vintage-engine cannot discover legacy JUnit 4 tests, so the class appears empty.
How to fix it
Use the matching @Test annotation
- For JUnit 5, import
org.junit.jupiter.api.Test. - For mixed suites, add the vintage engine so JUnit 4 tests still run.
- Re-run so the runner discovers the methods.
import org.junit.jupiter.api.Test;
class UserServiceTest {
@Test
void createsUser() { /* ... */ }
}Add the vintage engine for legacy tests
Keep running JUnit 4 tests on the JUnit 5 platform by including the vintage engine.
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")How to prevent it
- Standardize on one JUnit version and the matching
@Testimport. - Add the vintage engine while migrating from JUnit 4 to 5.
- Run the suite after migration to catch unrecognized classes.