I'm trying to test that calling a simple method in my Android app will start another activity. getNextStartedActivity
always returns the launcher activity.
Here is the test:
@Test
public void clickingButton_shouldStartNextActivity() throws Exception {
CurrentActivity activity = Robolectric.setupActivity(CurrentActivity.class);
activity.startNextActivity();
Intent expectedIntent = new Intent(activity, NextActivity.class);
assertEquals(expectedIntent, Shadows.shadowOf(activity).getNextStartedActivity());
}
And here is the startNextActivity method in CurrentActivity:
public void startNextActivity() {
startActivity(new Intent(this, NextActivity.class));
}
When I run the test, I get LoginActivity (launcher activity) as the actual result. Here LoginActivity in AndroidManifest.xml:
<activity
android:name=".LoginActivity"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>