Android Testing

Write Android unit, Compose UI, and Hilt-integrated tests. Use when designing test behavior with MockK or coroutine test utilities; defer database/WorkManager-specific recipes to the owning feature skill.

HoangNguyen0403 Updated 542 repo stars

File contents

Android Testing Standards

Priority: P0 (CRITICAL)

Implementation Guidelines

Unit Tests

  • Scope: ViewModels, Usecases, Repositories, Utils.
  • Coroutines: Use runTest (kotlinx-coroutines-test). Use MainDispatcherRule to mock Main dispatcher.
  • Mocking: Use MockK.

UI Integration Tests (Instrumentation)

  • Scope: Composable Screens, Navigation flows.
  • Rules: Use createAndroidComposeRule + Hilt (HiltAndroidRule).
  • Isolation: Fake repositories in DI modules (@TestInstallIn).

Anti-Patterns

  • No Real Network in Tests: Always mock with MockK or fake repositories via @TestInstallIn.
  • No Thread.sleep: Use IdlingResource or composeTestRule.waitUntil for async timing.

References

  • Test Rules

HoangNguyen0403/agent-skills-standard/tree/main/skills/android/android-testing commit ac95a4f3a5

Frequently asked questions

npx skillmds@latest add hoangnguyen0403/android-testing