Gitlab CI with Instrumentation Tests

Ankit Gupta
Fotonicia
Published in
2 min readJun 10, 2019

This post is in continuation with the previous post on deploying of artifacts to Fabric via Gitlab Pipeline.

The debugTests task in the Gitlab Pipeline in previous post only had unit tests. On any real Android project you would want to write down UI tests or instrumentation tests as well which can be integrated with your build process on Gitlab.

While unit tests can be run on a shared runner on CI/CD of Gitlab, the instrumentation tests require hardware acceleration which is not available on shared runners (as of now). So, the option one has is to configure your own machine as a runner that Gitlab can use to run CI/CD.

Thanks to this post, I used my spare linux desktop* as Gitlab Runner. Below is my .gitlab.yml section that I am using for instrumentation tests.

instrumentationTests:
stage: test
tags:
- android # tag with which our runner is started
before_script:
- ''
image
: shepeliev/android-sdk
script:
- /opt/start-default-emulator.sh
# Turn off animation
- adb shell settings put global window_animation_scale 0
- adb shell settings put global transition_animation_scale 0
- adb shell settings put global animator_duration_scale 0
# Turn off google auto-fill
- adb shell settings put secure autofill_service null
- ./gradlew cAT
only:
- /^master$/

Few things to note:

  1. I am using the tag android for the runner that I created.
  2. I have left the before_script empty since rest of my yaml script sets up the android sdk and platform tools dynamically.
  3. I am using the pre-built image shepelieve/android-sdk for the an emulator running API 28 on Pixel 2.
  4. Most tests require you to turn off the animations before running your UI tests so the adb shell settings commands are for those
  5. Lastly, the google auto-fill creates problems during the test execution for my test cases, so I have turned those off as well.
  • you may need to enable virtualization in your BIOS before being able to run the emulator. Use kvm-ok to check whether hardware acceleration is enabled or not.

If you liked this, connect with me on LinkedIn or Twitter.

--

--