I created android UI test with espresso and done Button click and opening an Activity. Now I want to validate whether opened correct activity or not.
Asked
Active
Viewed 764 times
2 Answers
0
You want get the instance of activity rule which you have register and compare it with the activity which you want.
// Define activity rule
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>
MainActivity.class);
// compare activity rule activity with the activity you want to check.
Assert.assertEquals(mActivityRule.getActivity(), MainActivity.class);

Jitesh Mohite
- 31,138
- 12
- 157
- 147
-
`getActivity()` returns the activity that the testrule has launched. This assertion will ALWAYS pass – Be_Negative Apr 01 '17 at 15:49
-
@Be_Negative These is the only way i guess you can validate these – Jitesh Mohite Apr 02 '17 at 15:17
-
But you are not validating anything here. What you are validating is that the activity in the test rule is indeed the activity that you want. What is the point? :) – Be_Negative Apr 02 '17 at 15:35
0
Use espresso-intents to validate that.
The usage is:
intended(hasComponent(NewActivity.class.getName()));
You can read this thread for more details on that: Espresso - check which Activity is opened using intent on button press?

Community
- 1
- 1

Be_Negative
- 4,892
- 1
- 30
- 33