0

In android I have a sample application with 2 Activities, MainActivity and DetailsActivity. In main activity, there is a list and a button, by pressing it the Details Activity is opened. In the intent, I put an ArrayList and an Object.

How can I Test that it works? Espresso Is it ok?

androidTestCompile 'com.android.support:support-annotations:25.3.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'



@RunWith(AndroidJUnit4.class)
@LargeTest
public class FirstTest {
    @Rule
    public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(
            MainActivity.class);

    @Test
    public void changeText_sameActivity() {

        onView(withId(R.id.fab)).perform(click());
        // How can i Specify the intent to the new Detail Activity?
    intended(hasComponent(new ComponentName(getTargetContext(), InsectDetailsActivity.class)));


        onView(withId(R.id.tv_original_title))
                .check(matches(withText( /* The text depends on the Passing Intent*/)));

    }
}
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125

1 Answers1

1

Duplicate question. See here. Here is the answer from that question:

intended(hasComponent(new ComponentName(getTargetContext(),ExpectedActivity.class)))
Josh Beckwith
  • 1,432
  • 3
  • 20
  • 38
  • I make some editings. I got an Wanted to match 1 intents. Actually matched 0 intents. And how can i pass all the intends Extras ? Should i create a mock ArrayList and Object to pass them to the newly created Activity, (Thanks) – Michael Marinos Likouras Jun 15 '17 at 14:33
  • You have to use intending with intended. Also you should use different test case for assertions related to different activities. – Amit Kaushik Jun 20 '17 at 06:54