# Test Flows And ViewModels

> Test state emissions without tapping the UI by hand.

- URL: https://dantech.academy/en/courses/kotlin-accelerator/engineer-builder/05-testing-security-release/lesson-02-test-flows-and-viewmodels
- Course: [Mobile Action Pro](https://dantech.academy/en/courses/kotlin-accelerator.md)
- Module: Testing, Security, and Release
- Duration: 6 min
- Difficulty: intermediate
- Access: Enrolled students
- Tiếng Việt: https://dantech.academy/courses/kotlin-accelerator/engineer-builder/05-testing-security-release/lesson-02-test-flows-and-viewmodels.md

## Objectives

- Write an emission ledger: collector first, trigger, drain virtual time, and only then assert
- Choose StateFlow for renderable state and SharedFlow for one-time UI events
- Control Dispatchers.Main and QzDispatchers in tests so ViewModel tests can run in commonTest

## In this lesson

1. Lesson Goal
2. Part 1: The Emission Ledger: StateFlow Or SharedFlow?
3. Part 2: Control The Clock In ViewModel Unit Tests
4. Part 3: A ViewModel Test That Runs On iOS
5. Part 4: Test A ViewModel's Sequence Or Its Settled State
6. Code Reading Path
7. Signs To Avoid
8. References
9. Key Points

## Study with an AI agent

The full lesson is for students of this course. Students open the lesson on the web and press **Markdown** to copy all of it, then paste it into Claude, ChatGPT, Cursor or whichever agent you use. Faster: mint a token at `/profile/ai-agents` and your agent reads lessons over MCP.

- [Join the course](https://dantech.academy/en/kotlin-accelerator/checkout)

---

- Previous lesson: [Test Reducers And Use Cases](https://dantech.academy/en/courses/kotlin-accelerator/engineer-builder/05-testing-security-release/lesson-01-test-reducers-and-use-cases.md)
- Next lesson: [Shrink And Protect The Android Release Build](https://dantech.academy/en/courses/kotlin-accelerator/engineer-builder/05-testing-security-release/lesson-03-shrink-and-guard-release-build.md)
