Skip to content

Instantly share code, notes, and snippets.

@maydin
Created November 12, 2016 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maydin/f7ca88f0e5db25ce19d6f1e54cc811fe to your computer and use it in GitHub Desktop.
Save maydin/f7ca88f0e5db25ce19d6f1e54cc811fe to your computer and use it in GitHub Desktop.
@LargeTest
@RunWith(AndroidJUnit4.class)
public class UserServiceTest {
@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<MainActivity>(MainActivity.class) {
@Override
protected void beforeActivityLaunched() {
App application = (App) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
TestUserComponent component = DaggerUserServiceTest_TestUserComponent.builder()
.testUserModule(new TestUserModule())
.build();
application.setUserComponent(component);
}
};
@Singleton
@Component(modules = {TestUserModule.class})
interface TestUserComponent extends UserComponent {
}
@Module
static class TestUserModule {
@Provides
@Singleton
UserService providesUserModule() {
return new TestUserService();
}
}
static class TestUserService implements UserService{
@Override
public String login() {
return "Test Logged in";
}
@Override
public String logout() {
return "Test Logged out";
}
}
@Test
public void userLoginLogoutTest(){
onView(withId(R.id.login_button)).perform(click());
onView(withText("Test Logged in")).check(matches(isDisplayed()));
onView(withId(R.id.logout_button)).perform(click());
onView(withText("Test Logged out")).check(matches(isDisplayed()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment