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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.