android-unit-testing
Run Android JVM unit tests via Gradle, collect reports, and fix failures. Use when asked to run/repair unit tests or CI test failures.
When & Why to Use This Skill
This Claude skill automates the execution and debugging of Android JVM unit tests using the Gradle build system. It streamlines the software development lifecycle by identifying relevant test tasks, analyzing failure reports, and implementing precise fixes for both production code bugs and flaky tests, ensuring high-quality Android application performance.
Use Cases
- Automated Bug Fixing: Rapidly identify and resolve failing unit tests in local development environments to maintain code integrity and prevent regressions.
- CI/CD Pipeline Recovery: Diagnose and fix unit test failures reported by continuous integration systems to unblock deployment pipelines and maintain build health.
- Multi-module Project Testing: Efficiently target and execute specific test variants (e.g., Debug, Release, or specific flavors) across complex Android project architectures.
- Flaky Test Mitigation: Refactor unreliable tests by isolating coroutines, mocking network IO, or removing time dependencies to improve test suite determinism.
| name | android-unit-testing |
|---|---|
| description | Run Android JVM unit tests via Gradle, collect reports, and fix failures. Use when asked to run/repair unit tests or CI test failures. |
Scope
- JVM unit tests (Gradle
test*UnitTest) first. - Instrumented tests are out of scope unless explicitly requested.
Preconditions
- Use the repo's Gradle Wrapper (
./gradlew). - Prefer deterministic commands; avoid “try random flags”.
Step-by-step
1) Discover test tasks
- List modules and test tasks:
./gradlew tasks --all | grep -E "test.*UnitTest|:test"
- Identify common tasks:
:app:testDebugUnitTesttestDebugUnitTest(root aggregation if present)- flavors:
test<Flavor><BuildType>UnitTest
2) Run unit tests
- First attempt (fast, useful output):
./gradlew testDebugUnitTest --stacktrace
- If multi-module, run the failing module task explicitly:
./gradlew :<module>:testDebugUnitTest --stacktrace
3) Collect evidence
- Always locate HTML report paths, e.g.:
<module>/build/reports/tests/
- Extract:
- failing test class/method
- assertion message
- stacktrace root cause
4) Fix strategy
- Prefer fixing production code bugs vs weakening tests.
- If test is flaky:
- remove time dependence
- isolate coroutines/dispatchers
- mock IO/network
- Keep changes minimal and explain tradeoffs.
5) Re-run and confirm
- Re-run the exact same command.
- If CI uses a different variant, also run that variant.
Output format
- Command(s) executed
- Failures summary (table)
- Root cause
- Patch + why
- Validation commands