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() {
}
For this purpose, try to use
Espresso Intents
library.Check: https://google.github.io/android-testing-support-library/docs/espresso/intents/index.html
and this example: https://github.com/googlesamples/android-testing/blob/master/ui/espresso/IntentsAdvancedSample/app/src/androidTest/java/com/example/android/testing/espresso/intents/AdvancedSample/ImageViewerActivityTest.java