Its been 2 weeks since I am studying Espresso and I could not grasp
public void shouldLaunchTagListActivity()
// should I intended or intending here?
The difference is
Intended only verifies that an Intent was launched (what you want).
Intending will return a result when the Intent is launched.
Intended (if you want to check if the intent did actually launched your activity)
This will fail if you press a button and launched, say, MyActivity, and you test
intended for TagListActivity. It will throw this following error:
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: Wanted to match 1 intents. Actually matched 0 intents.
Now, if you were testing that
onActivityResult was handled properly, you would use
Intending and pass in an
ActivityResult similar to this:
Intent resultData = new Intent(); resultData.putExtra("resultData", "fancyData"); ActivityResult result = new ActivityResult(Activity.RESULT_OK, resultData); intending(toPackage(HomeScreenActivity.class.getName())).respondWith(result)); // Perform action that throws the Intent onView(withId(R.id.imagebutton_tag)).perform(click()); // Verify your Activity is in the state it should be here.
So in this case, if you were expecting "HomeScreenActivity" to return something, you would use