Run a project's tests
android_testRun Gradle tests and report failures. Executes unit or instrumented tests, returning failing test names and condensed output for quick verification.
Instructions
Run a Gradle project's tests and report which ones failed.
This is the verification half of the loop: after changing code, prove the change works rather than assuming it. Failure output is condensed the same way android_build condenses it — you get the failing test names, not the whole Gradle log.
Two kinds of test:
'unit' runs testDebugUnitTest on the JVM. Fast, no device needed.
'instrumented' runs connectedDebugAndroidTest on a connected device or emulator. Slower, and requires a device.
Args:
project_path (string): absolute path to the Gradle root (contains gradlew)
module (string): module whose tests to run (default: 'app')
kind ('unit' | 'instrumented'): which test task to run (default: 'unit')
tests (string, optional): Gradle --tests filter, e.g. "com.example.MyTest" or ".LoginTest."
timeout_ms (number): timeout (default: 900000)
force (boolean): skip the JDK/Gradle compatibility pre-check (default: false)
response_format ('markdown' | 'json')
Returns: { "success": boolean, "task": string, // e.g. ":app:testDebugUnitTest" "durationMs": number, "failures": string[], // failing test names, when parseable "output": string, // condensed failure summary, or the tail on success "hint": string // present when the failure is a known one }
Examples:
Use when: you changed logic and want to know it still passes -> kind="unit"
Use when: narrowing to one failing test -> tests="com.example.CalcTest"
Use when: the behaviour only shows on a device -> kind="instrumented"
Don't use when: you only need the app compiled (use android_build)
Error Handling:
"instrumented" with no device connected fails at the device check, before Gradle starts
A project with no test sources reports success with an up-to-date task rather than a failure
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kind | No | 'unit' runs on the JVM; 'instrumented' runs on a connected device. | unit |
| force | No | Skip the JDK/Gradle compatibility pre-check. | |
| tests | No | Gradle --tests filter, e.g. 'com.example.MyTest' or '*.LoginTest.*'. | |
| module | No | Gradle module that produces the APK. Almost always 'app'. | app |
| timeout_ms | No | Timeout in milliseconds. | |
| project_path | Yes | Absolute path to the Gradle project root — the directory containing gradlew and settings.gradle. | |
| response_format | No | Output format: 'markdown' for human-readable, 'json' for machine-readable. | markdown |