PC パソコン

Android Studio: JUnit4 Parameterized Single Test Runs 0 Tests in AGP 9.4.0

When you run a single method from a JUnit4 @RunWith(Parameterized::class) instrumented test in Android Studio, the run may finish with “0 tests” instead of executing the selected parameterized cases. Google tracks this as a known Android Gradle Plugin (AGP) 9.4.0 issue, fixed for Android Studio Rabbit 2 | 2026.2.2 Canary 1.

Typical symptom

run finished: 0 tests, 0 failed, 0 ignored

<testsuites tests="0" failures="0" errors="0" skipped="0" .../>

A key clue is that running the entire parameterized test class works, while running only one test method from the Android Studio gutter produces zero discovered tests.

When this happens

  • Android Gradle Plugin 9.4.0 is in use.
  • The instrumented test uses JUnit4 Parameterized.
  • You run one test method directly from Android Studio.
  • Parameterized names produce method names such as bar[POLAND].

Cause

Android Studio passes a tests_regex filter when it launches a single parameterized method. With the AGP 9.4.0 test execution path, backslashes used to escape square brackets can be lost when the command is processed by the device shell.

-Pandroid.testInstrumentationRunnerArguments.tests_regex=pkg.FooTestSuite.bar\[.*\]

The escaped brackets are supposed to match the parameterized suffix literally. If the shell removes those escapes, the regular expression changes meaning and no longer matches the intended test names. The test process starts, but test collection returns zero matching tests.

Important: this is a test-selection/filtering problem rather than a normal assertion failure. If the class runs successfully but the individual method reports 0 tests, this AGP issue is a strong candidate.

Fix 1: Update to a fixed version

Google Issue Tracker marks Issue 558766788 as Fixed and targets Android Studio Rabbit 2 | 2026.2.2 Canary 1. When practical, update to an Android Studio/AGP combination that contains the fix.

Fix 2: Temporarily use AGP 9.3.1

The issue report states that the same workflow worked with AGP 9.3.1 before the upgrade to 9.4.0. If the problem started immediately after upgrading, temporarily reverting AGP can be used as a workaround.

plugins {
    id("com.android.application") version "9.3.1" apply false
}

Check compatibility with your Gradle, Android Studio, Kotlin, and project configuration before changing versions.

Fix 3: Run the whole parameterized class

Running the entire class avoids the problematic single-method regex filter. The official issue report specifically notes that the whole class works while the selected method returns zero tests.

Fix 4: Use a Run Configuration without bracket matching

The Issue Tracker describes a workaround using an Android Instrumented Tests run configuration. Target the class and pass a tests_regex instrumentation argument without the parameterized brackets.

-e tests_regex FooTestSuite#bar

This can select all parameterizations of the named method without relying on the bracket escapes that trigger the bug. Verify the resulting test set when using a custom runner or different naming scheme.

How to verify the problem

  1. Check the AGP version used by the project.
  2. Confirm the test uses JUnit4 Parameterized.
  3. Run the entire test class and confirm tests are discovered.
  4. Run one method from the same class and compare whether it reports 0 tests.
  5. Try the fixed toolchain, a temporary AGP 9.3.1 rollback, or the run-configuration workaround.
@RunWith(Parameterized::class)
class FooTestSuite(private val country: Country) {
    companion object {
        @JvmStatic
        @Parameterized.Parameters(name = "{0}")
        fun data() = listOf(Country.POLAND, Country.GERMANY)
    }

    @Test
    fun bar() {
        // test
    }
}

Notes

  • A normal failed test and a run that discovers zero tests are different problems.
  • If the entire class also discovers zero tests, check the test runner, source set, dependencies, and instrumentation configuration.
  • Treat an AGP downgrade as a temporary workaround and move to a fixed version when your project can do so safely.

Summary

If a single JUnit4 Parameterized instrumented test method runs as “0 tests” with AGP 9.4.0, the cause may be the known tests_regex escaping bug in the device-shell execution path. Prefer updating to a fixed version. Until then, running the full class, using a bracket-free regex filter in a Run Configuration, or temporarily reverting to AGP 9.3.1 can avoid the issue.

Official references