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.

Premium~20 min

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.

LayerRuns onSpeed (per test)What it can verify
JVM unitPlain JVM, no Android< 10 msPure logic, state machines, mappers, ViewModels with fakes
RobolectricJVM with shadowed Android50-200 msContext, Resources, SharedPreferences, simple lifecycle
Premium content

Unlock the complete breakdown.

Browse free problems