Run Android UI tests in Firebase Test Lab 2018

Firebase Test Lab provides cloud-based infrastructure for testing Android apps on physical and virtual devices

Mostafa Gazar
AndroidPub

--

I wrote a couple of posts previously about testing Android and iOS apps. In this post I am going to write about running your UI tests on physical and virtual devices using Firebase Test Lab.

The first thing we will need to do is to install gcloud on our machine so we can run the tests from command line either locally or on a CI machine.

$ curl https://sdk.cloud.google.com | bash 
$ exec -l $SHELL
$ gcloud init

Check out https://cloud.google.com/sdk/install#interactive for more details.

The second thing we need to do is to install gcloud beta components because testlab is still in beta.

$ gcloud components install beta

A quick test of our installation is always a good idea.

$ gcloud firebase test android models list

The next step is building our app, the following assumes that our UI tests flavor is called debug.

$ cd <AppFolder>$ ./gradlew :app:assembleDebug
$ ./gradlew :app:assembleDebugAndroidTest

You can check the out apks by running:

$ open app/build/outputs/apk/

Now the final and most important, running our UI tests.

$ gcloud firebase test android run \
--type instrumentation \
--app app/build/outputs/apk/debug/app-debug.apk \
--test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \
--device-ids hammerhead \
--os-version-ids 21 \
--locales en \
--orientations portrait

We can also use Firebase GUI to run our tests, by just running assembleDebug and assembleDebugAndroidTest and upload the output apks using Firebase console.

Follow me on Medium or Twitter to get notified about my coming posts.

--

--