Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@RunWith(AndroidJUnit4.class)
public class MainActivityUITest {
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
@Rule
public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule<>(MainActivity.class, true, false);
@Mock
MainActivityComponent.Builder builder;
@Mock
Utils utilsMock;
private MainActivityComponent mainActivityComponent = new MainActivityComponent() {
@Override
public void injectMembers(MainActivity instance) {
instance.mainActivityPresenter = new MainActivityPresenter(instance, utilsMock);
}
};
@Before
public void setUp() {
when(builder.build()).thenReturn(mainActivityComponent);
when(builder.activityModule(any(MainActivityComponent.MainActivityModule.class))).thenReturn(builder);
ApplicationMock app = (ApplicationMock) InstrumentationRegistry.getTargetContext().getApplicationContext();
app.putActivityComponentBuilder(builder, MainActivity.class);
}
@Test
public void checkTextView() {
String expectedText = "lorem ipsum";
when(utilsMock.getHardcodedText()).thenReturn(expectedText);
activityRule.launchActivity(new Intent());
onView(withId(R.id.textView)).check(matches(withText(expectedText)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment