Introduction to Espresso Testing
What is Espresso?
*Espresso is an instrumentation Testing framework made available by Google for the ease of UI Testing.
Espresso UI test automation framework for testing Android apps.
Few Expresso basics:
Espresso Free framework like Appium.
Espresso has fast feedback to its users which is a big advantage when it running on the device/emulator side-by-side with the app.
Espresso is an Android-only test automation framework. It doesn’t support cross-platform testing.
Espresso has unique synchronization method in its core making the tests less flaky and more robust. It will pass to the next test step in the code only once the view is available on the device screen as opposed to other tools that can easily fail without having timers, validation points and more.
The way it is easily used within Android Studio and Intelligent IDEA IDE’s makes it a powerful tool. It differentiates it from other open-source cross-platform.
- View Matchers (“find something“)
- allows you to locate a view in the current view hierarchy.
- View Actions(“do something”)
- allows you to interact with views.
- View Assertions(“check something”)
- allows you to assert the state of a view.
Espresso can fill the need for UI testing for your Android application, it really comes down to the scope of your testing. Android Studio organizes UI tests under the category name, androidTest and business logic tests under, test.
Using the Espresso Recorder
Android Studio is the Espresso Test Recorder is the useful test feature while using Espresso. Espresso tests by automatically recording interactions performed upon a device emulator.
Coverage Reports for Ensuring Quality
There are two basic metrics that are typically used to quantitatively determine code quality. These metrics are Pass/Fail percentage and Code Coverage.
Espresso basic syntax
- Find it ( matcher )
- Action on it ( view action )
- Check it ( Assertions view )
Select the test or test package you want to run in and Android Studio project pane. Then right-click the selection. You can Run the test, Debug a test, or run the test with Coverage.
When you select the coverage option, not only will the test be executed, but also a coverage report relevant to the test will be created.
View Test Results
After test execution ends, Android Studio shows the results in the Run pane on the lower left of the IDE. Also, the test coverage report will be available in the pane in the upper right of the IDE to ensure the test coverage.
Few more about Espresso
- Only java language is supported by Espresso.
- Supports only Android application.
- Espresso supports only white box testing.
- The flakiness of test is low.
- It’s easy to setup Espresso.
- Espresso supports object locators by id from R file.
- Bottleneck for every build.
- Long time to analyze results.
- Required more resources.