Skip to content
Latchkey

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.

JUnit
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

  1. For JUnit 5, import org.junit.jupiter.api.Test.
  2. For mixed suites, add the vintage engine so JUnit 4 tests still run.
  3. Re-run so the runner discovers the methods.
UserServiceTest.java
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.

build.gradle
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")

How to prevent it

  • Standardize on one JUnit version and the matching @Test import.
  • Add the vintage engine while migrating from JUnit 4 to 5.
  • Run the suite after migration to catch unrecognized classes.

Frequently asked questions

What causes "JUnit "No runnable methods""?
The class imports org.junit.Test (JUnit 4) but runs under JUnit 5 (org.junit.jupiter.api.Test), so Jupiter sees no test methods.
How do I fix JUnit "No runnable methods"?
Use the matching @Test annotation

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card