Huawei Developers
Published in

Huawei Developers

👨🏼‍💻Android UI Testing Made Easy: Espresso vs. Barista

You may have used Espresso before, but what about the Barista?

Hi, in this article what if I told you I will talk about a more simplified library than Android Espresso? Let’s check it out!


Android UI testing verifies the app’s user interface is working correctly and as expected. This helps improve the user experience, catch and fix bugs, and save time through automation.

Today we will cover the frequently used Android Espresso and the Android Barista frameworks.

Android Espresso is a testing tool created by Google for use in the Android Support Library, so you can use it in any Android app without adding any additional dependencies. It offers a straightforward and easy-to-use API for writing reliable tests for Android apps.

Android Barista is a another testing framework for writing UI tests. It’s built on top of Espresso and provides an easier-to-use for complex UI tests. It includes support for testing different app states and provides a robust API for interacting with the app’s UI.

Differences: Which One Is Better?

Actually, the choice of which one to use will depend on your specific needs and preferences.
So let me tell you the differences and you decide!

Espresso vs Barista


The implementation process is the same in both, after adding the relevant library to the dependecy section, you can now write a test!

androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
// Barista
androidTestImplementation('') {
exclude group: 'org.jetbrains.kotlin'

Also Barista already includes espresso-core and espresso-contrib


The use of a few examples of actions in Espresso and Barista. To access all: Espresso ActionsBarista Actions


  • Click — onView(withId(
  • Writing — onView(withId("A great text"))
  • Dialogs — onView(withText("OK")).inRoot(isDialog()).check(matches(isDisplayed()) .perform(click())
  • Scrolls —
    Here! Espresso will fail if the view is not inside a ScrollView


  • Click — ClickOn(
  • Writing — writeTo(, "A great text")
  • Dialogs — clickDialogPositiveButton()
  • Scrolls — scrollTo(R.string.text)

Barista seems more appropriate for ease of use, learn and to keep actions in mind while writing a test. Also Barista provides additional features and capabilities that are not available in Espresso, such as support for testing different app states, advanced support for testing custom views, and a more intuitive and reactive code structure. (For example, you cannot use Espresso for NestedScrollView) This makes Android Barista a more powerful and flexible testing framework than Espresso.


Here is an example of a simple test written with Android Espresso:

and with Android Barista:

See how easy it gets with the Barista? :)

Test Example for Login Form(Espresso — Barista)

Let’s write a test on the valid and invalid login scenarios for the Login Form. Think about which one you can do faster by reviewing the codes!



As you can see, the Android Barista test is more concise and easier to read than the Android Espresso test. This is because, as we mentioned earlier, Android Barista uses a more intuitive and reactive approach to testing.

One of the key advantages of Android Barista is that it allows developers to write tests that are more closely tied to the user experience of their app. This makes it easier to write tests that accurately simulate user interactions and verify that the app behaves as expected.


As a result; although the way of use depends on your performance and preference, we have also seen in the examples we examined that Barista has more readibility and usability. Since Barista is basically Espresso-based, we can say that it not only gives the same functionality, but also stronger with its reactive approach feature. Let’s remember the Barista’s slogan again: Barista, the one who serves a great Espresso. Good tests! ✌️

Glad if it helped, thanks for reading!
I’ll be waiting for your comments and claps!



As Huawei Developers, our Medium publication where we share information about the use of Huawei Ecosystem

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store