DaggerMock icon indicating copy to clipboard operation
DaggerMock copied to clipboard

Incompletion of workable test case in RealWorldAppInjector application

Open roman-yu opened this issue 6 years ago • 1 comments
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?

roman-yu avatar Jan 14 '19 10:01 roman-yu

It should work, which error do you get? Can you try to change it to understand the single change that makes it fail?

fabioCollini avatar Jan 17 '19 07:01 fabioCollini