Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Espresso leave the app after the test has finished? How to stop it from doing that

In Android Studio, in the androidTest folder, I have this test case:

@RunWith(AndroidJUnit4.class)
@LargeTest
public class LoginActivityTest {

    @Rule
    public ActivityTestRule<LoginActivity> activityTestRule =
            new ActivityTestRule<>(LoginActivity.class);

    @Test
    public void teamsListIsSortedAlphabetically() {
        onView(withId(R.id.etEmail)).perform(click(), replaceText("[email protected]")
        );
        onView(withId(R.id.etPassword)).perform(click(), replaceText("asdasd")
        );
        onView(withId(R.id.bLoginSubmit)).perform(click());
    }
}

The app launches LoginActivity, logs in, the next activity is shown for 1-2 seconds and then it exits the activity leaving me on the launcher screen. How do I make Espresso stay on that screen?

like image 545
Kaloyan Roussev Avatar asked Nov 30 '15 13:11

Kaloyan Roussev


People also ask

How do you dismiss an espresso dialog?

perform(pressBack()); this must dismiss your dialog. perform() requires a ViewAction and Espresso. pressBack() returns void . Would you like to add more details?

Does espresso support test recording?

The Espresso Test Recorder tool lets you create UI tests for your app without writing any test code. By recording a test scenario, you can record your interactions with a device and add assertions to verify UI elements in particular snapshots of your app.

How do espresso tests work?

Espresso tests state expectations, interactions, and assertions clearly without the distraction of boilerplate content, custom infrastructure, or messy implementation details getting in the way. Espresso tests run optimally fast!

How do you test espresso intent?

Validate intentsUsing the intended() method, which is similar to Mockito. verify() , you can assert that a given intent has been seen. However, Espresso-Intents doesn't stub out responses to intents unless you explicitly configure it to do so. // User action that results in an external "phone" activity being launched.


1 Answers

Sorry, but it's impossible.

Please read this Google reference: Automating User Interface Tests

Espresso, Robotium, Calabash and other UI test frameworks were made for short interaction testing events. It simulates an user's specific behavior - run app, do some tricks and (if successful) than close an app.

Of course, Espresso allow you to create custom idling resources and than register it in app.

The simplest way to hibernate a test for a specific amount of time is use method Thread.sleep(time_in_miliseconds), but like I said it's against idea of automated testing.

like image 179
piotrek1543 Avatar answered Oct 06 '22 01:10

piotrek1543