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.
Send a request to: https://groups.google.com/forum/#!forum/ctl-babbq-2015 to get added to the group. All members of this group get access to Cloud Test Lab.
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:
You can either download the sample code into your computer...
...or clone the GitHub repository from the command line.
$ git clone https://github.com/googlesamples/android-testing.git
$ ./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).
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.
With the code downloaded, the following instructions describe how to open the completed sample app in Android Studio.
BasicSampledirectory from the sample code folder (Quickstart > Import Project... >
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
$ 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.
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.
$ 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!