How To Test Your Android ViewModel UI State Updates
Easy ViewModel Testing With Kotlinx Coroutine Test And Turbine
When implementing Android apps, following the official architecture recommendations, you probably end up with a ViewModel
that has provided a StateFlow
of the managed view state to the UI. The UI can then delegate the various user actions to the view model and thus perform actions by which the view model updates the UI state depending on the outcome of those actions.
When following those guidelines, you will see that it’s recommended to not only implement and use your view models but also test them and their streams, including our view state StateFlow
updates.
In this article, we will pick up on one of my older articles about the Compose State Event library and see how we can test the ViewModel
UI state from this article with the help of the KotlinX Coroutine Test and Turbine library by Cash App.