Testing Android Flows in ViewModel with Turbine

<p>As it is common now, the correct architecture should contain decoupled layers. Inter-layer communication between them is done by streams, or in our case, flows, in Android. To make our solutions foolproof, we should create tests around every component, and the ViewModel is no exception. The more channels the ViewModel contains, the more challenging is to assert its complexity of it. The states should be emitted in a controlled way rather than in a chaotic.</p> <p>&nbsp;</p> <h1>Set up</h1> <p>Everything will be done without instrumentation tests, so the phone does not need to be connected.</p> <p>These are the required Android dependencies needed at the app&rsquo;s&nbsp;<code>build.gradle</code>&nbsp;for testing:</p> <p>Sample ViewModel</p> <p>The article will follow a simple ViewModel with one StateFlow (feel free to use the flow or any other channel), which carries all the information for any view. The ViewModel intakes one interface for mocking the repository, which does some work for a long time in the actual application.</p> <p><a href="https://proandroiddev.com/testing-android-flows-in-viewmodel-with-turbine-ea9bae7e811a">Read More</a></p>