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
- createComposeRule & Finders
- Assertions & Performing Actions
- Semantics & Test Tags
- Testing ViewModels & Flows