Is there a method to catch the invoked method in Activity under testing with Espresso

209 views Asked by At

I'm going to write the test code by using the Espresso library. But, I couldn't find a workaround for the below testing.

The testing module is Login module. After checking the user id and password, two methods will be invoked on the LoginActivity.

But, I don't know how to catch the invoked methods....

Below is my testing code snippet.

public class LoginActivityTest extends ActivityInstrumentationTestCase2<LoginActivity> {

public LoginActivityTest() {
    super(LoginActivity.class);
}

@Override
public void setUp() throws Exception {
    super.setUp();
    getActivity();
}



public void testLoginSuccess() {
    onView(withId(R.id.username)).perform(typeText("[email protected]"));
    onView(withId(R.id.password)).perform(typeText("secret"));
    onView(withId(R.id.loginButton)).perform(click());

    // I think I have to write code snippet down here.
}

}

The login activity have a two callback methods by using the interface.

@Override
public void loginSuccessful() {
    ...
}

@Override
public void showError() {
}
1

There are 1 answers