This page is deprecated. Redirecting to https://developer.android.com/studio/test/espresso-test-recorder.html
Espresso Test Recorder is a new feature released in Android Studio 2.2 Preview 3 that makes it easy to generate automated UI tests by recording your own interactions on a device so you don't have to actually write any test code. The generated test code can then be used to run against a wide variety of device configurations to make sure your application works as expected. This will not only make you more productive, but it will also significantly increase the test coverage and quality of your app.
Espresso Test Recorder creates tests based on the Espresso Testing framework, which is part of the Android Testing Support Library (ATSL). To learn more about ATSL and Espresso refer to our best practices for testing guide.
Recording a test using Espresso test recorder is really simply.
A Device Chooser dialog appears, which lets you select a target device.
To record a user flow, you first need to choose a device. Espresso test recorder supports all kinds of devices: physical devices, virtual devices and cloud devices. To record using your own device, connect it and select it under Connected Devices. To record using an emulator, select a device from Available Emulators or create a new virtual device by clicking Create new Emulator. Then click OK.
Espresso test recorder will now run a full build of your project and then show the Record your test window. If you see a dialog on your device saying "Attaching Debugger," this is expected because Espresso test recorder is using the debugger to log UI events.
To record UI events start interacting with your device and you will see how the events are logged while you click through the user flow.
Because you haven't interacted with your device yet, the panel on the left says "No events recorded yet."
Espresso Test Recorder logs a "Tap" event on the button with the ID fab_add_notes and the device updates to show the notes detail screen where you can enter the title of a new note.
Typing the text "Happy Testing!" into the Title input results in a new "Type" event for the view with the ID add_note_title.
Clicking the button with the ID fab_add_notes saves the note and logs the corresponding UI "Tap" event. Next, verify that the new note is displayed in the notes list.
Clicking the Add Assertion Button creates an interactive screenshot of the current screen. You can then click on the "Happy Testing!" text, that you want to verify against. This will automatically pre-populate all the assertion values, the ID of the view, the view assertion (text is), and the text that you want to verify.
Clicking the Save Assertion button logs an "Assert" event to the recording. The final step is to click Complete Recording, to generate the Espresso test code.
Saving your test in the previous step will immediately show the generated Espresso test code. Even though this is generated test code, the concise and fluent Espresso API makes it easy to read, understand and customize it to your needs.
Right-click on the generated AddNotesScreenTest class and click Run AddNotesScreenTest. For more options to run your tests from Android studio tbd.
The generated test code can be run on your local development machine, on your Continuous Integration server CI, or on Firebase Test Lab. Moreover it can be used as a great learning tool for testing and working with the Espresso testing framework.
Technical docs >