View on GitHub

reading-notes

Espresso

Espresso Testing:

Use Espresso to write concise, beautiful, and reliable Android UI tests.

The following code snippet shows an example of an Espresso test:

        @Test
        public void greeterSaysHello() {
            onView(withId(R.id.name_field)).perform(typeText("Ahmed"));
            onView(withId(R.id.greet_button)).perform(click());
            onView(withText("Hello Ahmed!")).check(matches(isDisplayed()));
        }

Synchronization capabilities

Each time your test invokes onView(), Espresso waits to perform the corresponding UI action or assertion until the following synchronization conditions are met:

Synchronization capabilities

The main components of Espresso include the following:

Ridiculous superpower: the Espresso Test Recorder

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. Espresso Test Recorder then takes the saved recording and automatically generates a corresponding UI test that you can run to test your app.

Record UI interactions

To start recording a test with Espresso Test Recorder, proceed as follows:

Add assertions to verify UI elements

Assertions verify the existence or contents of a View element through three main types:

resources:

https://developer.android.com/training/testing/espresso

https://developer.android.com/studio/test/espresso-test-recorder