Created
November 12, 2016 10:28
-
-
Save maydin/f7ca88f0e5db25ce19d6f1e54cc811fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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