The general flow to using espresso-intents is this:
- Call
intending(X).respondWith(Y)
in order to set up the mock.
- Perform the action which should result in the intent being sent.
- Call
intended(Z)
to verify that the mock received the expected intent.
X and Z could be identical, but I tend to make X as generalised as possible (e.g. only match the component name), and make Z be more specific (check values of extras, etc.).
e.g. For ZXing I might do something like this (warning: I haven't tested this code!):
Intents.intending(hasAction("com.google.zxing.client.android.SCAN"); // Match any ZXing scan intent
onView(withId(R.id.qr_scan_button).perform(click()); // I expect this to launch the ZXing QR scanner
Intents.intended(Matchers.allOf(
hasAction("com.google.zxing.client.android.SCAN"),
hasExtra("SCAN_MODE", "QR_CODE_MODE"))); // Also matchs the specific extras I'm expecting