Why mock a Repository dependency in a ViewModel unit test?

This tests your grasp of test isolation. A great answer says mocking eliminates real database or network dependencies so you can verify ViewModel state changes in isolation. A red flag is insisting on using the real Repository inside the unit test.
This tests your understanding of unit test isolation and why ViewModels should not depend on real external data sources. A strong answer outlines three ideas: first, mocking a Repository lets you control return values and error conditions deterministically; second, it keeps tests fast by avoiding real database or network I/O; third, it lets you verify that the ViewModel transforms data and exposes correct UI state. A red flag is arguing that mocking adds complexity or that integration tests replace the need for isolated ViewModel tests.
Read the original → developer.android.com
- #android
- #unit-testing
- #mockito
- #viewmodel
- #repository
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.