JUnit 5 Testing: Android Unidirectional Data Flow with LiveData
summary
Starting from Coinverse's LiveData + UDF Kotlin app, the talk shows a concrete test workflow: modularize viewmodel and repository, mock repository flows with MockK, run synchronous LiveData on test dispatchers, and assert view states/effects with AssertJ under JUnit 5. The codebase yields 96% code coverage for viewmodel lines by 61 focused unit tests, with utilities for mocking paged lists, static/constants, and coroutine test dispatchers so tests run off-device.
AI-written summary · about
chapters (12)
- 0:00Introduction and motivation
- 3:52High-level overview of plan
- 6:23Why UDF with LiveData and Kotlin
- 13:27Local unit testing strategy
- 17:41Test configuration setup
- 21:53Parameterized tests and edge cases
- 23:18Mocking repository and data
- 26:31Firing events and assertions
- 28:58Verification and cleanup
- 30:22Test coverage and results
- 30:44Next steps and recap
- 31:47Q&A and closing remarks
related talks
24mUsing Kotlin Flow in MVVM
38mMigrating from LiveData to Coroutines and Flow
43mEffective Unit testing with Kotlin
22mReactive, Clean Architecture and Android Architecture Components, a solid formula for a MVVM based a
41mViewModels, LiveData and Lifecycles, oh my!
19mFun with LiveData
22mUnit Testing with KotlinFlow
42mBuild testable apps for Android
