How to check expected intent sent without actually launching activity in Espresso? : <p>I have a UI test which clicks a button, and then launch a new Activity in its onClickListener. The test checks whether expected intent is sent or not.</p>

<p>My problem is, I want to test whether expected intent is sent <strong>without actually launching the activity</strong>. Because I found that new activity initializes its state, and it makes subsequent tests flaky. </p>

<p>I know there are two <a href="https://google.github.io/android-testing-support-library/docs/espresso/intents/index.html" rel="noreferrer">Espresso Intents</a> api, which are <code><a href="https://developer.android.com/reference/android/support/test/espresso/intent/Intents.html#intended(org.hamcrest.Matcher%3Candroid.content.Intent%3E)" rel="noreferrer">intended</a></code> and <code><a href="https://developer.android.com/reference/android/support/test/espresso/intent/Intents.html#intending(org.hamcrest.Matcher%3Candroid.content.Intent%3E)" rel="noreferrer">intending</a></code>, but both fail to meet my needs. <code>intended</code> api actually launches the target activity, and <code>intending</code> api doesn't launch the activity, but it calls <code>onActivityResult</code> callback which I don't want either. Because I'm afraid that code inside <code>onActivityResult</code> may cause another flakiness. Also <code>intending</code> doesn't assert whether matching intent is sent, it just calls <code>onActivityResult</code> callback when matching intent is found, which means I have to check whether <code>onActivityResult</code> is called or not!</p>

<p>Is there any clean way to achieve what I want?</p>
