android-testinglisted
Install: claude install-skill eric-sabe/engsys
# Android Testing
Write and review tests for Android/Kotlin targeting JUnit, MockK, Turbine,
kotlinx-coroutines-test, Robolectric, Espresso, and Compose UI testing. Favor a
test pyramid: many fast JVM unit tests, fewer Robolectric/Compose tests, and a
thin layer of instrumented end-to-end tests. Test behavior, not implementation.
## Contents
- [Test Pyramid and Source Sets](#test-pyramid-and-source-sets)
- [Unit Tests (JUnit)](#unit-tests-junit)
- [Mocking with MockK](#mocking-with-mockk)
- [Testing Coroutines](#testing-coroutines)
- [Testing Flows with Turbine](#testing-flows-with-turbine)
- [Testing ViewModels](#testing-viewmodels)
- [Robolectric](#robolectric)
- [Compose UI Testing](#compose-ui-testing)
- [Espresso](#espresso)
- [Common Mistakes](#common-mistakes)
- [Review Checklist](#review-checklist)
## Test Pyramid and Source Sets
| Location | Runs on | Use for |
|---|---|---|
| `src/test/` | Local JVM (`testDebugUnitTest`) | Logic, ViewModels, repos, mappers, Robolectric |
| `src/androidTest/` | Device/emulator (`connectedDebugAndroidTest`) | Espresso, Compose UI, integration |
Keep most tests in `src/test/` — they are fast and run in the unit-test gate.
Reserve `src/androidTest/` for tests that genuinely need a device/emulator.
## Unit Tests (JUnit)
JUnit 4 is still the Android default; JUnit 5 is fine for pure-JVM modules with
the platform engine configured. Name tests by behavior.
```kotlin
class PriceFormatterTest {
@Test
fun `formats whole dollar