By: Made Sudarsana, Mitrais Analyst Programmer
What is Espresso?
Espresso is an Android Java library that specifically helps Android developers to test applications via the user interface of the application. Espresso helps us to easily emulate actions such as click, scroll, touch and also to turn on many event listeners within Android mobile applications. In Android Studio there is also functionality to record user actions then compile them into UI Testing classes. Google released the Espresso framework in Oct. 2013. Since its 2.0 release Espresso is part of the Android Support Repository.
UI Testing is a technique used to identify the presence of defects by interacting directly with the user interface of the application. Usually this technique records user actions first, then replays them for future testing. It can radically minimize human error compared to testing manually through the application.
Espresso Basic Features
- View Matcher
This feature gets the object view of the current activity or fragment by Id of the component.
- View Action
This feature enables our test to perform click, scroll, input text etc.
- View Assertion
This feature compares the return result of actions with the desired result
To start recording a test with Espresso Test Recorder in Android Studio, proceed as follows:
- Click Run > Record Espresso Test
- In the Select Deployment Target window, choose the device on which you want to record the test. Click OK
- Espresso will build your project, and install the app and launch before allowing you to interact with it. Now you can interact with your device and start logging events such as “click” and “type” actions.
The left window (see above) show us all the actions that have been performed by the user in the Application. When you add an assertion, it will display the application interface on the right hand side. This window helps us to pick a component of assertion and state the desired result.
Once you have finished with your action, make sure you add an assertion result. Then you can save your recording Test Class on the Android Test package which can be re-used for future tests. To run saved tests you can right click then run the test. Android Studio will launch your application and run the test through the user interface.
The main benefit that developers get from Espresso is the ability to automatically execute Unit tests and functional tests from within either their IDE or as part of a continuous integration pipeline. This means each build will validate every change that has been made. Espresso is integrated in the latest Android Studio which can record, reply and modify through test classes. It makes UI Testing in Android much easier and feels like you are writing a story for the user on how to use the application.
Espresso: https:// developer.android.com/studio/test/espresso-test-recorder.html