How to do it…

In Espresso, we mainly have three components:

  • ViewMatchers: Allows you to find a view in the current view hierarchy. This can be done in various ways, such as searching by id, name, child, and so on. You can also use Hamcrest matchers, such as containsString.

  • ViewActions: Allows you to perform actions on the views, such as clicking, typing, clearing text, and so on.

  • ViewAssertions: Allows you to assert the state of a view that checks whether the condition under the view assertion passes.

Let's take a look at the following steps to understand acceptance testing using Espresso:

  1. Here's an example of a text matcher (a text matcher matches the text; it's a part of ViewMatchers):
onView(withId(R.id.textView)).check(matches(withText(not(containsString("Hello"))))); ...

Get Kotlin Programming Cookbook 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.