Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Gradle finds no tests to run in an Android local unit test

ErrorThe :app:testDebugUnitTest task runs but reports that no tests were found or executed

Short 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.

  • Applies to Android Gradle Plugin 8.x and 9.x, Gradle 8.x and 9.x, JUnit 4.13, JUnit Jupiter 5.x, Android Studio current stable
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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*
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2Jupiter 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. 3The same build runs other tests fine, and the report names your filter textThe --tests filter does not match the class or method nameFix

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" --info

Confirmed by docs.gradle.org

Did this fix it?

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" --info

Confirmed by docs.gradle.org

Did this fix it?

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" --info

2Fix

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" --info

Confirmed by docs.gradle.org

Did this fix it?

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

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 fix

Mobile 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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.