Issue
I am runnning Espresso testing and I want to test 2 items:
- Click of a button in Fragment X
- The TextView contains text in Activity Y
code:
@RunWith(AndroidJUnit4.class)
public class AsyncTest {
private static final String TEST_TEXT = "TEST_TEXT";
@Rule
public ActivityTestRule<MainActivity> mActivity = new ActivityTestRule(MainActivity.class);
@Test
public void testIfResultIsEmpty() {
Espresso.onView(ViewMatchers.withId(R.id.first_button))
.perform(ViewActions.click());
/* How do I check that text has populated? */
Espresso.onView(ViewMatchers.withId(R.id.random_joke))
.check();
}
Solution
matches(isDisplayed())
would at least check if the view is being displayed - while one barely can check for the text of a random joke, where one would assume some random text... unless loading a specific text for testing purposes, which is then being known - and could be compared/matched (as explained recently in the RecyclerView answer, the ActivityTestRule
could be used to pass an ITEM_ID
, so that one would have a specific item to compare the views to).
onView(withId(R.id.random_joke)).check(matches(isDisplayed()));
and one does not have to use Espresso, but can try findViewById()
and then assertNotNull()
.
Answered By - Martin Zeitler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.