Gradle finds no tests to run in an Android local unit test
The :app:testDebugUnitTest task runs but reports that no tests were found or executedShort answer
Gradle ran the test task but the test engine it used found nothing that matched. In Android modules this is usually a JUnit 4 or JUnit 5 mismatch: JUnit 5 tests need useJUnitPlatform(), and JUnit 4 tests need the Vintage engine once that platform is on. Check the engine, then the --tests filter.
Fix it fast
1Find out which cause you have
Run the one test class with info logging, and see which engine ran. Then check which JUnit libraries the module declares.
./gradlew :app:testDebugUnitTest --tests "com.example.CalculatorTest" --info grep -n "junit\|useJUnitPlatform" app/build.gradle*2Match what you see, then jump to its fix
- 1
The class uses org.junit.jupiter.api.Test or @ParameterizedTest, and nothing is reported as runJUnit 5 tests are running on the JUnit 4 defaultFix - 2
Jupiter tests run and JUnit 4 classes (@RunWith(Parameterized::class), org.junit.Test) report no testsThe JUnit Platform is on, but old JUnit 4 tests have no engineFix - 3
The same build runs other tests fine, and the report names your filter textThe --tests filter does not match the class or method nameFix
- 1
What does the error look like?
The :app:testDebugUnitTest task runs but reports that no tests were found or executed
Cause 1 of 3
JUnit 5 tests are running on the JUnit 4 default
1Check
Gradle's test task runs JUnit 3 and 4 classes unless you switch it to the JUnit Platform. A Jupiter test class is then not a test at all as far as it can tell.
grep -n "useJUnitPlatform\|jupiter" app/build.gradle*2Fix
Add the Jupiter dependency, which includes the parameterised-test support, and turn on the JUnit Platform for the unit test tasks of the module.
// app/build.gradle.kts
android {
testOptions {
unitTests.all {
it.useJUnitPlatform()
}
}
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.11.0")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}3Verify
The class now shows its test cases as executed.
./gradlew :app:testDebugUnitTest --tests "com.example.CalculatorTest" --infoConfirmed by docs.gradle.org
Cause 2 of 3
The JUnit Platform is on, but old JUnit 4 tests have no engine
1Check
Once useJUnitPlatform is on, only engines on the test runtime classpath run. JUnit 4 classes need the Vintage engine.
grep -n "vintage\|junit:junit" app/build.gradle*2Fix
Add the Vintage engine and keep JUnit 4 on the classpath, so one run covers both old and new tests.
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.11.0")
testCompileOnly("junit:junit:4.13.2")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.11.0")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}3Verify
Run the old class and see its cases listed.
./gradlew :app:testDebugUnitTest --tests "com.example.OldJUnit4Test" --infoConfirmed by docs.gradle.org
Cause 3 of 3
The --tests filter does not match the class or method name
1Check
A --tests pattern that begins with a capital letter is read as a simple class name; any other pattern is read as fully qualified. A package typo, or a method name that does not exist, leaves nothing selected.
./gradlew :app:testDebugUnitTest --tests "*CalculatorTest" --info2Fix
Use the full name of the class, or a wildcard, and check method names against the source.
./gradlew :app:testDebugUnitTest --tests "com.example.CalculatorTest"
./gradlew :app:testDebugUnitTest --tests "*CalculatorTest"3Verify
The test report lists the tests that ran.
./gradlew :app:testDebugUnitTest --tests "com.example.CalculatorTest" --infoConfirmed by docs.gradle.org
How do I stop it coming back?
- Pick one test framework per module, and write its engine into the build file next to the dependency.
- Run the whole unit test task in CI as well as single classes, so a module with no matching engine fails loudly.
- Keep JUnit and Gradle versions listed in one version catalog.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile apps
Android Studio cannot pair the phone over Wi-Fi
The Pair devices over Wi-Fi dialog lists no device
Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.
4 causes, each with a fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fixMobile apps
adb tcpip 5555 fails because no device is found
adb: more than one device/emulator
adb tcpip only works while the device is attached and listed by adb, because it tells the phone to start listening on port 5555.
4 causes, each with a fix