Android Architecture Component ViewModel - How to mock ViewModel on test Activity?
问题 I'm trying to setup UI testing similar to GithubBrowserSample and it looks like the sample project only has mock ViewModel for Fragment but not an example for Activity . Here's my code where I am trying to test the Activity by mocking ViewModel . But the ViewModel is not getting set before onCreate() in Activity. @RunWith(AndroidJUnit4::class) class MainActivityTest { val viewModel = mock(MainViewModel::class.java) @Rule @JvmField val activityRule = ActivityTestRule<MainActivity>(MainActivity