The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.

Testing with Espresso

Basic JUnit4 instrumentation tests are fine for testing non-UI logic. They even work acceptably for some basic UI testing. The more complex your UI testing gets, though, the more likely it is that you will find plain JUnit4 instrumentation tests to be limiting and tedious.

In particular, running tests across activities can be tricky with ordinary JUnit4. ActivityTestRule is designed for testing a single activity in isolation, and crafting your own rule that transcends a single activity may be difficult.

Espresso is designed to simplify otherwise-complex UI testing scenarios, such as:

In this chapter, we will explore how to set up basic Espresso tests and how to employ them as part of your overall testing implementation.


This chapter assumes that you have read the chapter on JUnit4.

Adding a Shot of Espresso

The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.

Writing Tests in Espresso

The preview of this section was eaten by a grue.

The Espresso Test Recorder

The preview of this section was traded for a bag of magic beans.

Stronger Espresso

The preview of this section was whisked away by a shark-infested tornado.

Opting Out of Analytics

The preview of this section was the victim of a MITM ('Martian in the middle') attack.

Waiting for the World to Change

The preview of this section apparently resembled a Pokémon.