Introduction to Espresso Testing

by Sayooj K S

on June 12, 2018

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.

Espresso Framework

  • 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.

Running Tests

     Espresso basic syntax

  1. Find it ( matcher )
  2. Action on it ( view action )
  3. 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.

Subscribe to our Newsletter

  • Share this Article

GET IN TOUCH WITH iLEAF

  • We can initiate development process at the hour of your convenience
  • Discussion on the projects can be held for a stipulated duration
  • We will sign NDA and the talks will be secured
  • We’ll show you around our cherished designs
  • Briefing on technology
  • Guaranteed source code delivery
  • Option to re-start a closed venture

See how we can unwrap your app idea and proceed towards success