Instrumentation Testing in Android

Introduction

Instrumentation tests are executed on an Android device. They can interact with the Android framework APIs and emulate real conditions. They’re useful in testing the application’s behavior on a real device. These tests are slower than unit tests since they depend on Android APIs.

These tests use the instance of the Instrumentation class for application context. The class also provides APIs to control the app being tested.

In this lesson, we’ll learn to write instrumentation tests using Android’s Espresso UI testing framework.

Gradle dependencies

We need to add the Espresso library dependencies in the app/build.gradle file to start unit testing in our app.

Get hands-on with 1200+ tech skills courses.