Neon Warge Neon Warge - 1 year ago 136
Android Question

Whats the difference between intending vs intended in Espresso?

Its been 2 weeks since I am studying Espresso and I could not grasp

. When do I use
intending and
intended`? The provided example and online tutorials are not helping and researching the web is doing me more damage than good.

Semantically, for intellectual reference, why is it
and the other
, this added more to the confusion. Is this another Google naming blunder or its just me? These two method really doesn't make sense.

I am misunderstanding its usage. I wanted to test if my activity
launched activity
. That's it. Here is my code:

public void shouldLaunchTagListActivity()




// should I intended or intending here?
// ???


This test always pass even I supplant the intent with the wrong the target.

I can check if the other activity has been launched by checking if my target view is existing and was seen by the user. But now I am going to run on a different user story where I really need to check if the activity sent the request to launched another activity (my activity, not external).

Any explanation is greatly appreciated!

Answer Source

The difference is Intended only verifies that an Intent was launched (what you want). Intending will return a result when the Intent is launched.

For 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:$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);


// Perform action that throws the Intent

// 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 Intending.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download