Error When Stubbing Intent with Espresso
<p>I have two applications that interact with each other through intents. I would like to verify that let's say <em>App A</em> correctly calls the <code>startActivity</code> for <em>App B</em> without actually launching <em>App B</em>. I have tried various combinations of <code>intending</code> and Espresso still launches <em>App B</em> through the intent instead of just stubbing it out. This causes the remaining tests to fail as the UI is blocked by <em>App B</em>. Any ideas?</p>

<pre><code>@RunWith( AndroidJUnit4.class )
@LargeTest
public class MyActivityUiIntentsTest
{

    @Rule
    public IntentsTestRule&lt;MyActivity&gt; activityRule =
            new IntentsTestRule&lt;&gt;( MyActivity.class, true, false );

    @Test
    public void shouldStartOtherActivityWhenButtonClicked ()
    {
        Intents.init();
        intending( toPackage( "my.package" ) )
            .respondWith( new ActivityResult( Activity.RESULT_OK, null ) );

        activityRule.launchActivity( new Intent() );

        onView( withId( R.id.viewId ) ).perform( click() );
        intended( hasComponent( hasShortClassName( "the.other.class.name" ) ) );

        Intents.release();
    }
}
</code></pre>

<p><strong>UPDATED:</strong> Code for the <code>onClick</code>:</p>

<pre><code>@OnClick( R.id.viewId )
public void startOtherActivity ()
{
   Intent intent = new Intent();
   intent.setClassName( "my.package", "the.other.class.name" );
   startActivity( intent );
   finish();
}
</code></pre>