Core Concepts
Testing
The Android test pyramid in practice - JVM unit tests, Robolectric on the JVM, instrumentation on a device, plus the doubles and screenshot tools that make the layers work.
Every shipped Android feature survives three test environments: a plain JVM, a JVM with Android shadowed in, and a real or emulated device. Picking the right one for a given assertion is the discipline. This page covers the pyramid - unit / Robolectric / instrumentation - plus the doubles, DI, and screenshot tools that decide how much of the suite sits at the cheap layers. The layer-separation prereq is Architecture; Compose test rule and StateFlow-under-test patterns are touched on here and unpacked in Compose and State Management.
The Android test pyramid
The pyramid is three execution environments stacked by cost, with a "shift left" rule that pushes every test as far down as it can correctly live.
| Layer | Runs on | Speed (per test) | What it can verify |
|---|---|---|---|
| JVM unit | Plain JVM, no Android | < 10 ms | Pure logic, state machines, mappers, ViewModels with fakes |
| Robolectric | JVM with shadowed Android | 50-200 ms | Context, Resources, SharedPreferences, simple lifecycle |