fbpx
Hero Illustration
0 Comments
Software Development

Espresso: A Hot Tool for Android UI Testing

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

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

  1. View Matcher

This feature gets the object view of the current activity or fragment by Id of the component.

  1. View Action

This feature enables our test to perform click, scroll, input text etc.

  1. View Assertion

This feature compares the return result of actions with the desired result

Espresso Recording

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

  1. Click Run > Record Espresso Test
  2. In the Select Deployment Target window, choose the device on which you want to record the test. Click OK
  3. 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.
Espresso Recording

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.

Conclusion

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

Contact us to learn more!

Please complete the brief information below and we will follow up shortly.

    ** All fields are required
    Leave a comment