unit-test-android

Validate Android unit tests for local versus instrumented boundaries and test doubles.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/sunzhk/shared-skills --skill unit-test-android
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unit-test-android
Source: https://github.com/sunzhk/shared-skills/tree/main/unit-test-guide-skills/unit-test-android
Command: npx skills add https://github.com/sunzhk/shared-skills --skill unit-test-android

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

本技能帮助 Android 项目建立与维护可重复、可验证的单元测试体系,明确本地单元测试与仪器化测试的边界,提供可替换的依赖与测试改造建议。

Core Features & Use Cases

  • 本地单元测试 vs 仪器化测试的明确区分与使用场景
  • 通过注入依赖、使用 fake/stub/mock 提升可测试性
  • 给出 Given-When-Then / Arrange-Act-Assert 风格的测试编写规范
  • 测试放置规范:本地测试放在 module/src/test,仪器化测试放在 module/src/androidTest
  • 提供可维护的测试边界和错误处理思路

Quick Start

在 Android 模块中将单元测试放在 module/src/test,仪器化测试放在 module/src/androidTest,然后开始编写聚焦的测试。

Frequently Asked Questions about unit-test-android

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write deterministic Android unit tests for ViewModel logic?

Deterministic Android unit tests for ViewModel logic are achieved by isolating dependencies through test doubles like fakes or mocks and placing the tests in the module/src/test directory to ensure local execution without device dependencies.

What is the difference between local unit tests and instrumented tests in Android?

Local unit tests run on the JVM and are placed in module/src/test, while instrumented tests run on a device or emulator and belong in module/src/androidTest, with boundaries enforced to separate pure business logic from Android framework dependencies.

Where should I place Android unit tests for Kotlin business logic?

Android unit tests for Kotlin business logic should be placed in module/src/test to ensure they execute locally as pure JVM tests, keeping them isolated from instrumented tests in module/src/androidTest.

How do I isolate dependencies when unit testing Android ViewModel layers?

Isolate dependencies in Android ViewModel unit tests by injecting fake, stub, or mock test doubles, replacing real Android framework components to ensure test execution remains deterministic and isolated from external states.

What structure should I use for Android unit test assertions?

Android unit test assertions should follow the Given-When-Then or Arrange-Act-Assert style, ensuring a minimum set of assertions that clearly verify the expected behavior of the Kotlin or Java business logic.

Can I use this approach for unit testing Java business logic in Android apps?

Yes, this approach applies to both Kotlin and Java business logic across typical Android app architectures, enforcing test placement boundaries and dependency isolation for reliable unit-level verification.