Issue
I have two applications that interact with each other through intents. I would like to verify that let's say App A correctly calls the startActivity for App B without actually launching App B. I have tried various combinations of intending and Espresso still launches App B through the intent instead of just stubbing it out. This causes the remaining tests to fail as the UI is blocked by App B. Any ideas?
@RunWith( AndroidJUnit4.class )
@LargeTest
public class MyActivityUiIntentsTest
{
@Rule
public IntentsTestRule<MyActivity> activityRule =
new IntentsTestRule<>( 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();
}
}
UPDATED: Code for the onClick:
@OnClick( R.id.viewId )
public void startOtherActivity ()
{
Intent intent = new Intent();
intent.setClassName( "my.package", "the.other.class.name" );
startActivity( intent );
finish();
}
Solution
Move your intending... code below launchActivity and remove .init() because the IntentsTestRule will call init for you after the activity is launched
Answered By - Nick Korostelev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.