Check if a new Activity is started with Espresso

Lefteris' solution or this code works:

intended(hasComponent(MainActivity.class.getName()));

But don't forget to change ActivityTestRule to IntentsTestRule too.

 @Rule
 public IntentsTestRule<LoginActivity> mLoginActivityActivityTestRule =
            new IntentsTestRule<>(LoginActivity.class);

Rather than using intended, try using intending, it worked for mine.


Well The solution is to check this way:

intended(hasComponent(OnboardingActivity::class.java.name))

In order to perform this check, you need to add the intents library (androidTestImplementation "androidx.test.espresso:espresso-intents:$intentsVersion") and init it by calling:

Intents.init()