Android Testing Standards
Priority: P0
Implementation Guidelines
Unit Tests
- Scope: ViewModels, Usecases, Repositories, Utils.
- Coroutines: Use
runTest(kotlinx-coroutines-test). UseMainDispatcherRuleto 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.