New feature: SofySense – Manual test case & test results AI generator to help you speed up your testing process. Try it today.  

Sofy launches product feature suite to deliver effortless test maintenance and ensure continuous precision – learn more.

sofy logo
Sofy x Venomous Vector, Shutterstock

Is Android’s Espresso Growing Cold?

Android’s Espresso does exactly what it should do. But does it cut it as a modern mobile application testing framework? Let's take a look.

What’s going on with Espresso? When it comes to mobile app testing, developers choose from hundreds of options, and it’s not unusual for multiple tools and frameworks to be used in the testing process.

Consider the mobile testing pyramid: We have unit testing at the bottom as the base of the pyramid, providing the functional tests that verify the API behavior. This is followed by integration tests above in the middle, which test how well components play together. Finally, there’s end-to-end (UI) testing at the top, which tests how users interact with your application. Android’s Espresso is at the top of the pyramid when it comes to testing Android mobile applications.

We all know that mobile application development doesn’t end the day of go-live, and neither does testing. It’s a process that prioritizes consistent and sustained testing that provides smooth rollouts of new features every time. And smooth is what your users have come to expect these days.

What is Espresso?

Espresso is a UI testing framework for Android mobile applications. Developed by Google in 2013, Espresso is now part of the Android support repository.  With Espresso, developers write automated test cases in Java using a lightweight API, synchronized with your mobile application’s user interface. This provides quick feedback. It can then be run on a mobile emulator or real device. Espresso allows you to test UI elements that make your user interface engaging, and the behaviors and state that your users depend on.

How does Espresso work?

Simple and powerful is how most would define Espresso’s code base and capability. The Java-based framework relies on three primary components. These components involve navigating through views – building blocks of UI – to match, perform actions, and assert against.

The three components are:

  • ViewMatchers: ViewMatchers allows developers to write functions to match any view present on the UI. Matchers can match a view by its unique ID, or by way of a variety of match criteria that developers can specify.
  • ViewActions: A second component, ViewActions, performs an action on a given element. Use easy to understand functions like click(), swipeLeft(), typeText(), doubleClick(). Anything you can do with a keyboard and mouse, you can perform through Java using ViewActions.
  • ViewAssertions: Responsible for performing assertions on the view element. These verify that the view found is the view expected. These assertions can check if the view contains a string, is positioned a certain way, or behaves as expected. Assertions are what determine if the test is passing or failing.

With these lightweight and simple API commands, Espresso allows even Java beginners to quickly write powerful test automation. What’s more is that Espresso is native to Android, and so for many developers on the platform, it’s a familiar tool.

Why would you want to use Espresso?

There are significant benefits to using Espresso. For example:

  • Simple, concise code: The Espresso’s Java library will be easy for anyone with a light understanding of Java to approach. Even non-technical folks might be able to peek at a test case and know what’s going on.
  • Stability: Since Espresso is written in code and references view elements, it’s more stable than a record/playback framework that relies on more transient components.
  • Speed: When it comes to code-based UI testing, the speed of writing Espresso test cases is second to none.
  • Synchronization: With Espresso, your UI elements synchronize so that you test what you want to test. Espresso waits for synchronization criteria to be met before running your test. This limits the need to put wait or pause on anything.
  • Fast, reliable feedback: Espresso doesn’t rely on any server-side communication, and in turn delivers fast test results. 

So, why wouldn’t you want to use Espresso?

Fair question. 

Let’s start with the biggest complaint. We live in a world of multiple devices, multiple platforms, and multiple operating systems. In today’s day and age, it’s all about scaling to the demands of users on whatever device they’re on. Espresso can only be used to test mobile Android applications. This means that if you develop apps for multiple platforms, you’ll have to use a different framework or tool for each version, as you can’t reuse any of the tests you’ve created using Espresso, and that’s a huge drawback.

Other Espresso limitations

But that’s not all. Consider the following:

It’s code.

Sure, we’ve discussed how easy Espresso’s code is to approach, but it’s still code. That means you still need reliable access to developer skills and, in turn, specialists. Abstraction marches ever onward, and so modern frameworks are increasingly moving to no-code, providing access to a wide range of citizen testers. This is a huge, ongoing shift and one well worth paying close attention to.

Too specific.

Espresso focuses solely on client-side UI testing. As a result, there’s no mocking, stubbing, or deep application testing, which would be available to you in a more robust framework. This means that you’ll have to use additional methods for your testing strategy.

No cross-platform testing.

Android designed Espresso for testing Android mobile applications and Android mobile applications only. Espresso doesn’t offer browser testing or other device testing. In a world that’s increasingly about getting an app published on all mediums, Espresso might not be the best fit for you.

Local to the app.

You need the application source code to test since it relies on the IDs of the view elements.

Limited language support.

Espresso only supports tests written in Java, so if you’re talented with other languages, you may not get to use them here.

Open-Source.

The framework is open-source, which means free. That always comes with a trade-off. For example, there’s no way to rely on support and no promise that the tools you need will be developed into the future.

Takeaways

In short, I recommend trying Espresso if:

  • you’re sticking with Android app development, and only Android app development
  • you only need UI testing and have the other areas of the pyramid covered elsewhere
  • you’ve got developer bandwidth with a Java skill set

Yet you’d be wise to look somewhere else if you:

  • require more robust testing capabilities, like mocking and stubbing 
  • lack the developers to write Java code
  • need a tool that supports cross-platform testing across multiple devices and operating systems

Conclusion

No tool is perfect. All-in-all, Espresso does exactly what it was created to do and it does it well. If you’re developing Android mobile applications, Espresso’s rich testing capabilities might be just what you need. However, if you’re hoping for a more robust testing tool and you’re looking to maximize your efficiency, you’d be wise to keep in mind Espresso’s limitations.

Disclaimer: The views and opinions expressed above are those of the contributor and do not necessarily represent or reflect the official beliefs or positions of Sofy.