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 Gradle for Android, 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 was whisked away by a shark-infested tornado.

Gradle and Android Studio Settings

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

Creating a Test Case

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

Running Your Tests

The preview of this section may contain nuts.

Finding Your Widgets

The preview of this section was last seen in the Bermuda Triangle.

Using the UI Automator Viewer

The preview of this section will not appear here for a while, due to a time machine mishap.