0Pricing
Jetpack Compose Academy · Lesson

Testing ViewModels & Flows

Unit-test logic with test dispatchers.

Test Logic Without the UI

A ViewModel holds your screen logic, so you can test it directly with plain JUnit. No emulator or rendering needed, which makes these tests fast. ⚡

Arrange, Act, Assert

ViewModel tests follow a simple rhythm: create the ViewModel, call a function, then assert the new state. Keep each test focused on one behavior.

val vm = CounterViewModel()
vm.increment()
assertEquals(1, vm.count)

All lessons in this course

  1. createComposeRule & Finders
  2. Assertions & Performing Actions
  3. Semantics & Test Tags
  4. Testing ViewModels & Flows
← Back to Jetpack Compose Academy