Quick revision
The short answer
The usual causes are mismatched JUnit Platform versions on the classpath after the upgrade, tests that are still JUnit 4 without the Vintage engine, test classes that no longer match Surefire's include patterns, and a Surefire configuration (provider, groups, excludes or a skip flag) that filters everything out. We find which one with mvn dependency:tree and Surefire's debug output, fix it with the JUnit BOM, and make it impossible to miss with failIfNoTests and a CI check that compares test counts with the previous build.
What to remember
In this answer, we followed the chain from Surefire's includes through the JUnit Platform and its engines to the tag filters, and saw that a break anywhere produces Tests run: 0 with a passing build. The likely causes after an upgrade are mismatched platform versions, which dependency:tree reveals and the BOM fixes; JUnit 4 tests without the Vintage engine; and configuration that filters everything out, such as includes, groups or a forced old provider. Surefire's failIfNoTests and a CI comparison of test counts between builds make the next zero impossible to miss.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The usual causes are mismatched JUnit Platform versions on the classpath after the upgrade, tests that are still JUnit 4 without the Vintage engine, test classes that no longer match Surefire's include patterns, and a Surefire configuration (provider, groups, excludes or a skip flag) that filters everything out. We find which one with mvn dependency:tree and Surefire's debug output, fix it with the JUnit BOM, and make it impossible to miss with failIfNoTests and a CI check that compares test counts with the previous build.
Why this question is asked
A module that goes from 300 tests to zero and still passes is one of the most dangerous build failures, because nothing turns red. The upgrade looks successful, the team moves on, and the module now ships without any test protection. Interviewers ask this because finding the cause needs a systematic approach, and because the real lesson is about making silent failures loud. In this answer, we will see how Surefire decides which tests to run, go through the likely causes one by one with the command that confirms each, and then add two safety nets so a zero can never pass unnoticed again.
1How Surefire Finds Tests
To diagnose a zero, it helps to know the chain that must work for a test to run. Surefire first selects class files by name, using its includes patterns (by default classes named Test*, *Test, *Tests and *TestCase) and excludes. Then it chooses a provider based on what it finds on the test classpath; with JUnit Platform present it uses the platform provider. That provider starts the JUnit Platform Launcher, which asks every test engine on the classpath to discover tests in those classes, applying any tag filters from groups and excludedGroups.
A break anywhere in that chain gives the same symptom. If no engine recognises the tests, if the classes are filtered out by name, or if a tag filter removes everything, the Launcher simply reports an empty test plan, and Surefire prints Tests run: 0.
- Class names match includes?YesPass the class to the platformNoExcluded by name: 0 tests
- Platform jars on matching versions?YesLauncher starts the enginesNoEngine fails or finds nothing
- An engine recognises the tests?YesTests discoveredNoJUnit 4 tests without Vintage: 0 tests
- Tag filters keep any tests?YesTests runNogroups or excludedGroups removed all: 0 tests
4 steps in order. Play them, or step through them one at a time.
Every 'no' branch gives the same output: Tests run: 0, BUILD SUCCESS.
2Cause 1: Mismatched JUnit Platform Versions
The upgrade may have brought in a library that depends on an older or newer junit-platform-engine or junit-platform-commons than the rest. When the engine and the platform disagree, the Jupiter engine can fail to initialise or the launcher can quietly skip it; depending on the versions, we see a warning such as an engine failing to discover tests, an error, or just nothing (check the exact message for your versions). mvn dependency:tree shows the truth.
The fix is to import junit-bom in dependencyManagement, so every JUnit artifact, including the transitive ones, is forced to the same version. With Spring Boot, the Boot dependency management does this as long as nobody overrides one artifact by hand.
3Cause 2: JUnit 4 Tests Without the Vintage Engine
If the module's tests import org.junit.Test, they are JUnit 4 tests. Before the upgrade, junit:junit was on the classpath and Surefire ran them with its JUnit 4 provider, or the Vintage engine came in transitively, for example through an older spring-boot-starter-test that included it. After the upgrade, the JUnit Platform is on the classpath, so Surefire uses the platform provider, but without junit-vintage-engine no engine recognises JUnit 4 tests. Jupiter ignores them, because they are not annotated with its @Test.
A quick search for 'import org.junit.Test;' in the module confirms or rules this out in seconds.
4Cause 3: Names and Filters That Exclude Everything
The remaining causes are all configuration, and they usually arrive through a parent POM that changed with the upgrade. The first link in the chain is the class name. A team that names its tests *Spec or *Should relies on an explicit includes pattern, and if the new parent replaces the plugin configuration, that pattern is gone and every class is dropped before JUnit even sees it. The last link is the tag filter. If the parent now sets groups=integration for a CI profile, a module whose tests carry no tags matches nothing, so the platform returns an empty plan.
In between sits the provider choice. Some old POMs declare a provider such as surefire-junit47 as a dependency of the plugin, which forces the JUnit 4 provider even when Jupiter is present, and that provider cannot see Jupiter tests. A skip flag, skipTests or maven.test.skip, looks similar at first glance, but Surefire then prints 'Tests are skipped' rather than a zero, which is a useful way to tell it apart.
The fastest way to see which applies is to look at the effective configuration and Surefire's debug log.
5Making a Zero Impossible to Miss
Once fixed, we make sure the next zero fails the build. Surefire has a failIfNoTests parameter: when true, the build fails if no tests were run. We set it in the modules that are expected to have tests, or in the parent POM with an opt-out property for modules that genuinely have none. That catches the total collapse to zero.
It does not catch a drop from 300 to 120, for example when half the classes stop matching the includes. For that, a CI check compares the executed test count per module, read from the XML reports, with the previous successful build on the main branch and fails or alerts when it drops by more than a set amount, say 10 percent, unless the pull request says that tests were removed on purpose.
Notice that the error also says how to switch the check off, which is exactly what a module with no tests should do explicitly. The exact message varies a little between Surefire versions, but the effect is the same: zero is now a failure.
6Follow-up questions
Why did the build pass with zero tests in the first place?
Because from Surefire's point of view nothing failed. It ran the test plan the platform gave it, and that plan was empty. Most build tools treat 'no tests' as a valid outcome, since many modules legitimately have none, so we have to say explicitly which modules must have tests.
Is Gradle any safer here?
The classic Gradle trap is forgetting useJUnitPlatform(), which gives the same silent zero. Newer Gradle versions fail a test task that finds test sources but runs no tests (check your version), which is a good default, but a count comparison in CI is still useful for partial drops.
7Conclusion
In this answer, we followed the chain from Surefire's includes through the JUnit Platform and its engines to the tag filters, and saw that a break anywhere produces Tests run: 0 with a passing build. The likely causes after an upgrade are mismatched platform versions, which dependency:tree reveals and the BOM fixes; JUnit 4 tests without the Vintage engine; and configuration that filters everything out, such as includes, groups or a forced old provider. Surefire's failIfNoTests and a CI comparison of test counts between builds make the next zero impossible to miss.
Open with
Tests run: 0 with a green build means the JUnit Platform got an empty test plan, so I would check each link in the chain. First, version mismatch: an upgraded library may bring an older or newer junit-platform-engine or commons than Jupiter expects, so the engine fails or finds nothing.
Then, if they want more
I would run mvn dependency:tree filtered to org.junit, and fix it by importing junit-bom so every JUnit artifact is forced to one version. Second, JUnit 4 tests: if the tests still import org.junit.Test and the Vintage engine is no longer on the classpath, perhaps because a starter stopped including it, Jupiter ignores them.
A grep for the import tells me quickly, and the fix is adding junit-vintage-engine or migrating. Third, configuration: class names that no longer match Surefire's includes, a groups filter inherited from a parent that selects a tag these tests do not have, a too broad exclude, or an explicitly declared JUnit 4 provider. help:effective-pom and mvn -X show those.
Then I would make it impossible to miss: set failIfNoTests to true in modules that must have tests, so zero fails the build, and add a CI check comparing the executed test count per module with the previous main-branch build, alerting on a drop of more than about ten percent, which catches partial losses too.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- JUnit 4
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- JUnit user guide
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "After a dependency upgrade, mvn test reports 'Tests run: 0' for a module that has 300...": https://scrivio-interview-library.netlify.app/java/junit/8156040dab/