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 UI Automator

Yet another approach for testing Android applications is UI Automator. This is designed for integration testing, both how your app components integrate with one another (e.g., activities starting activities) and how your app components integrate with the rest of a device, including other applications.

In early 2015, Google released version 2.0 of the UI Automator framework. This update ties UI Automator into the same instrumentation testing engine that is used for JUnit4 testing. This also makes it possible to run UI Automator tests through Android Studio and the Android Gradle Plugin, which previously had been difficult.


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

What Is UI Automator?

UI Automator, as the name suggests, automates UIs. It simulates user input, in the form of tapping on items and the like. It does so without modifying your process’ contents. Tests run by UI Automator are implemented in JUnit, and those tests have limited access to the widgets inside of a UI. Such access not only allows for directing simulated user input (e.g., “click the OK button”), but also for asserting that various test conditions are true (e.g., “does the list have five rows?”). In this respect, UI Automator behaves like traditional Android JUnit testing.

Why Choose UI Automator Over Alternatives?

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

Gradle and Android Studio Settings

The preview of this section was eaten by a grue.

Creating a Test Case

The preview of this section took that left turn at Albuquerque.

Running Your Tests

The preview of this section was eaten by a grue.

Finding Your Widgets

The preview of this section was lost due to a rupture in the space-time continuum.

Using the UI Automator Viewer

The preview of this section was accidentally identified as an Android 'tasty treat' by the Cookie Monster.