Issue
I need to write a UI test to validate that clicking the floating action button results in displaying the SecondActivity.
public class MainActivityTest {
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
MainActivity.class);
@Before
public void setUp() throws Exception {
}
@Test
public void onClick() throws Exception {
onView(withId(R.id.button)).perform(click());
}
}
Is it enough?
And how can I validate that the Activity properly displays the text contents of an incoming object: name, age, phone number?
I have just started using espresso(
Solution
Is it enough?
No, it is not enough. This code
onView(withId(R.id.button)).perform(click());
only performs a click on the button, but there is nothing that verifies that the application behaved correctly after that.
To verify that an intent to open the SecondActivity was created, you need to use Espresso Intents.
how can I validate that the Activity properly displays the text contents of an incoming object
You can use something like:
onView(withId(R.id.textView)).check(matches(withText("Expected text")));
Take a look at the Espresso Cheatsheet for more.
Answered By - Philippe A
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.