The general flow for using espresso intent is as follows:
- Call
intending(X).respondWith(Y) to customize the layout. - Take an action that should result in the sending of the intent.
- Call
intended(Z) to verify that the layout has the expected intention.
X and Z can be the same, but I tend to make X as generalized as possible (for example, only matching the name of the component) and make Z more specific (check the values of additional parameters, etc.).
eg. For ZXing, I could do something like this (warning: I have not 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
source share