jeudi 27 septembre 2018

Android, Espresso - Activity stops before whole test is finished when run as part of :app:connectedAndroidTest (runs fine in isolation)

I apologise if this is a bit too vague here, but I'm not allowed to post my whole actual code. All I can say is I have a problem running this test as a part of ./gradlew connectedAndroidTest

@RunWith(AndroidJUnit4.class)
@LargeTest
public class MobileAppSanityTest extends AbstractEspressoTest {

    @Rule
    public ActivityTestRule<MainActivity> mActivityRule =
        new ClearPreferencesActivityTestRule<>(MainActivity.class, getFiles());

    @Override
    protected Context getContext() {
        return mActivityRule.getActivity();
    }

    @BeforeClass
    public static void beforeAll() {
        RoboGuice.Util.reset();
    }

    @Test
    public void test_SingleUserFlow() {
        navigateSplashScreen();
        logIn();
        doSomethingElse();
    }
}

What happens here is that when I run this test class on its own - it runs fine, but when I run it as a part of 'connectedAndroidTest' the activity is stopped right after 'navigateSplashScreen' and login cannot be performed.

Error I get is:

 java.lang.RuntimeException: No activities found. Did you t to launch the activity by calling getActivity() or startActivitySync or similar?

I'm quite new to Espresso and Android in general, so it's a bit hard to wrap my head around this. Please let me know if you need more information. I'll try to provide it out if that's the case.

Aucun commentaire:

Enregistrer un commentaire