Google Cloud Test Lab provides cloud-based infrastructure for testing Android apps. With one operation, you can initiate testing of your app across a wide variety of devices and device configurations. Test results — including logs, videos, and screenshots — are made available in your project in the Google Developers Console. Even if you haven't written any test code for your app, Cloud Test Lab can exercise your app automatically, looking for crashes.

In this codelab, you'll learn how to get started with using Cloud Test Lab for testing your mobile apps. You'll be able to run your tests from the web, Android studio, or using our "gcloud" command line interface. You can even integrate it to your Continuous Integration environment.

What you'll learn

What you'll need

Join the BABBQ Cloud Test Lab attendees group

Send a request to:!forum/ctl-babbq-2015 to get added to the group. All members of this group get access to Cloud Test Lab.

Create a Google Cloud Platform Project with billing enabled

For the purpose of this codelab, we already added all the attendees to a special project that meets the necessary requirements. If you wish to use your own project, you should:

Get the sample code

You can either download the sample code into your computer...

Download Zip

...or clone the GitHub repository from the command line.

$ git clone

Build your code using gradle

$ ./gradlew :app:assembleDebug
$ ./gradlew :app:assembleDebugAndroidTest
$ ls app/build/outputs/apk/

The fastest and easiest way to start your tests is through the web. All you need to start your instrumentation test is the application's APK and the test APK. To run your first test you can do the following:

In just a few clicks, we were able to start our tests on a wide variety of devices and configurations, using infrastructure that would've otherwise taken a very long time to build and maintain, while providing access to devices you might not even have access to.

Now we will try starting a test on a different set of devices. Let's integrate this into our development environment by using it during Development from Android Studio or during code check-in from our Continuous Integration Environments (e.g. Jenkins).

Install Android Studio and Enable the Cloud Test Lab Plugin

If you haven't already installed Android Studio, download and install it here. Make sure you install version 1.4+ for Cloud Test Lab to work.

For Android Studio 1.4, you still need to do the an additional step to enable the plugin:

Now, you should be able to see the additional options for Cloud Test Lab in Android Studio's Run/Debug configurations dialog.

Import the sample project

With the code downloaded, the following instructions describe how to open the completed sample app in Android Studio.

  1. Select the BasicSample directory from the sample code folder (Quickstart > Import Project... > android-testing > ui > espresso > BasicSample).
  2. Install any missing packages and resolve suggested conflicts
  3. Click the Gradle sync button. Resolve all issues.
  4. If you encounter any issues, follow the suggestions from Android Studio to install missing packages until you completely resolve the issue.

Run a Cloud Test Lab test from Android Studio

Install "gcloud" command-line interface and enable Cloud Test Lab plugin

Now that we've used Cloud Test Lab from Android Studio and ensured that our code works during development, let's take it one step further and use it from the command-line, which is the first step towards a more formal Continuous integration with our deployment workflow.

$ gcloud components update alpha
$ gcloud config set project cloud-test-lab-babbq-2015
$ gcloud auth login

Run a Cloud Test from "gcloud" command-line interface

$ gcloud alpha test android run \
  --type instrumentation \
  --app app/build/outputs/apk/app-debug-unaligned.apk \
  --test app/build/outputs/apk/app-debug-androidTest-unaligned.apk \
  --device-ids Nexus6,Nexus7 \
  --os-version-ids 19,21 \
  --locales en,fr \
  --orientations portrait,landscape
$ gcloud alpha test android devices list
$ gcloud alpha test android run \
  --type instrumentation \
  --app app/build/outputs/apk/app-debug-unaligned.apk \
  --test app/build/outputs/apk/app-debug-androidTest-unaligned.apk \
  --device-ids k3g \
  --os-version-ids 19 \
  --locales en,fr \
  --orientations portrait,landscape


Using a service account tells gcloud that the user is a robot. This avoids checks for spam and prevents having the account mistakenly blocked or prompted for captchas.

Add a build step to Jenkins

Robo Tests

Robo tests are what we call "Something for nothing". We need nothing but the app itself, and the crawler will explore it in an attempt to encounter a crash. The crawler is a smarter version of Android Monkey which understands different elements on the screen and explores them in a depth-first search manner to get deterministic results on different paths in the applications and paths to crashes if encountered any.

Running the Robo tests from the web interface

Running the Robo tests from gcloud command-line interface

$ gcloud alpha test android run \
  --type robo \
  --app app/build/outputs/apk/app-debug-unaligned.apk \
  --device-ids k3g \
  --os-version-ids 19 \
  --locales en,fr \
  --orientations portrait,landscape


You have now tried different uses for Cloud Test Lab and passed a major milestone towards achieving better quality for your app!

What we've covered

Next Steps

Tell us how we did