JUnit "No tests found / No runnable methods" in CI - Fix Test Discovery
When the build reports "No tests found" or "No runnable methods", the test runner discovered zero tests to run. Either the class/method naming does not match the discovery pattern, or the annotations belong to a JUnit version whose engine is not on the classpath.
What this error means
The build passes suspiciously fast with No tests found / Tests run: 0, or a class fails with No runnable methods (JUnit 4 finding no @Test). CI is green but nothing actually ran.
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[WARNING] No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)Common causes
Class/method names do not match the include pattern
Surefire by default includes *Test, Test*, *Tests. A class named MyTestCase or methods without @Test are silently skipped, yielding zero tests.
JUnit version/engine mismatch
JUnit 5 @Test (org.junit.jupiter) with only the JUnit 4 runner present (or vice versa) finds no runnable methods. No runnable methods is the classic JUnit 4 form.
How to fix it
Match naming or widen the include pattern
Rename classes to the convention, or configure Surefire to include yours, and fail the build if none run.
<configuration>
<includes><include>**/*Test.java</include><include>**/*IT.java</include></includes>
<failIfNoTests>true</failIfNoTests>
</configuration>Align the JUnit engine with the annotations
- For JUnit 5, depend on
junit-jupiterand a Surefire 3.x that auto-detects the platform. - For mixed JUnit 4 + 5, add
junit-vintage-engineso old tests still run. - Set
failIfNoTests=trueso an empty discovery fails CI instead of passing green.
How to prevent it
- Follow the
*Test/*ITnaming convention, setfailIfNoTests=true, and keep the JUnit engine matched to the annotations you use.