DaggerMock
DaggerMock copied to clipboard
Incompletion of workable test case in RealWorldAppInjector application
trafficstars
It is currently in below version:
@Test
public void testOnCreate() {
when(restService.executeServerCall()).thenReturn(true);
Robolectric.setupActivity(MainActivity.class);
}
which I changed to below version:
@Mock MainPresenter presenter;
@Test
public void testOnCreate() {
when(restService.executeServerCall()).thenReturn(true);
MainActivity activity = Robolectric.setupActivity(MainActivity.class);
activity.findViewById(R.id.reload).performClick();
verify(presenter).loadData();
}
But it failed due to fail to mock presenter. It seems failed to mock the MainPresenter or I am doing some wrong?
It should work, which error do you get? Can you try to change it to understand the single change that makes it fail?