I am trying to better know the structure of espresso for testing in android, however, I had a problem trying to mock my host.
First of all, I use the adapted MVP architecture for my application. So I use something like View (Activity) -> Presenter -> Model -> Presenter -> View to make a request and update the user interface.
My activity after creating will make a request to update the entire user interface and, after receiving the result, updates the user interface accordingly.
public class MyActivity extends AppCompatActivity implements IPresenter{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_activity); new Presenter().doRequestToUpdateUI(); } @Override public void onResponseReceived(UIObject uiOject){ findViewById(R.id.button).setVisibility(uiOject.getVisibility()); } }
However, for this, doRequestToUpdateUI () requires some previous authentication, and therefore it is necessary for the hole presenter to taunt in order to check the other user interface of my activity.
Is there a way to mock my presenter and put it into action, or at least not do anything when calling the doRequestToUpdateUI () method.
I do my test this way, but still not working.
@LargeTest @RunWith(AndroidJUnit4.class) public class MyActivityInstrumentationTest { @Mock public Presenter presenter; @InjectMocks public PresenterMock mPresenterMock; @Rule public ActivityTestRule<MyActivity> mActivityTestRule = new ActivityTestRule<MyActivity>(MyActivity.class, true, false) { @Override protected void beforeActivityLaunched() { presenter = Mockito.mock(Presenter.class); Mockito.doNothing().when(presenter).doRequestToUpdateUI(); super.beforeActivityLaunched(); } }; @Test public void simpleTestCheck() { mActivityTestRule.launchActivity(new Intent());
iGoDa source share