I want to test the following flow in my application:
I want to test this flow using espresso. I think I have to use intended or intending 1 but I an not sure how to check if the intent was ZXing and how to come back to the application.
The general flow to using espresso-intents is this:
intending(X).respondWith(Y)
in order to set up the mock.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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With