Testing with Espresso

Testing UI components can be difficult. Knowing when a view has been inflated or ensuring you don't access views on the wrong thread can lead to strange behavior and flaky tests. This is why Google has released a helper library for UI-related instrumentation tests called Espresso (https://code.google.com/p/android-test-kit/wiki/Espresso).

Adding the Espresso library JAR can be achieved by adding to the /libs folder, but to make it easier for Gradle users, Google released a version to their Maven repository (consider yourselves lucky users because this was not available before version 2.0). When using Espresso, you need to use the bundled TestRunner as well. Therefore, the setup becomes:

dependencies { // other dependencies ...

Get Learning Android Application Testing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.