At AVG Innovation Labs we are constantly experimenting and exploring new ways to solve our problems, and sometimes this results in discovering some very interesting possibilities.
One such case happened during the development of AlarmClock Xtreme, one of the most popular alarm clocks on Play Store with more than 30-million installs. To ensure good product quality before shipping, we have several automated tests in place.
The challenge? At some point during the development, we realised that some of the Android Instrumentation Tests were slowing down the build-server pipeline. This was because the tests were executed on an emulator on the build-server and could take more than 20 minutes.
Harnessing the power of Pi
To speed up things, naturally we decided to try running our automation tests on actual physical devices. But before investing in a ton of new hardware, I realised we had a number of Raspberry Pi microcomputers lying around the office.
This got me thinking perhaps we could use these as a cheap and energy efficient devices to power our tests. So we started exploring whether it was possible and if it’d even be fast enough.
Sure enough, we got something working and here’s how we did it.
Setting up Pi with ADB
First make sure you have the latest Raspbian Jessie (or similar) image installed on Pi.
Then run the following commands to install ADB:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install android-tools-adb
If all goes well, try connecting an android device to the Pi with a USB. A permissions dialog should appear immediately on the device which you should allow. Then issue the command:
If your device appears in the list (as in figure-2), then you’re ready to run android tests:
Joining the dots between build server and Pi
Now you need to make sure that your build server can find your raspberry-pi and can connect to it. Here I will show you how to do that if you’re running a Jenkins based build server. You can create a new slave node and give it the IP-address of your PI. A sample slave node configuration is shown below.
Create a new Slave-Node in Jenkins and configure it as shown in Figure-3.
In the “Host” field make sure to give the IP-Address of your Pi. You can find that our by using the ifconfig command on your PI. In Credentials you need to give the user/password for connecting to your PI. Keep the “# of executors” field to 1 so that there is not too much load on the PI.
Don’t forget to also give the path to the “Remote root directory”, this is where your project files and newly built. apk files will be copied by Jenkins.
Once this is set up, launch the slave agent on the Jenkins and you will see the output of the established connection and a message indicating that slave agent is running successfully.
Configuring the test-automation jobs
Next use the adb commands to install your test.apks, which are built by Jenkins, and then run the instrumentation tests. When you create a release build, along with your release .apk file which goes to the store, an extra “androidTest-unaligned” apk file is also created in the outputs/apk folder. You need to have both of them installed on your Android phone to run the tests :
adb install <your_path>-androidTest-unaligned.apk
adb install <your_path_to_release_apk>.apk
adb shell am instrument -e emma true –w <your_app_package>/android.test.InstrumentationTestRunner
If these commands run successfully on your system then, you will see on the Jenkins console the list of all the Tests which are executed and which of the Tests failed.
The time taken to run the tests went down from 20 minutes on an emulator to under 5 minutes with a physical device attached to Pi.
This shows the Raspberry Pi is well capable of handling Android Instrumentation Tests. In comparison to an emulator running on a full system, it can also perform better with a physical device.
So not only, can you use your Pi for hobby hacking over the weekend, but it looks like people can also try it out for some serious Android development.
I’d love to hear from the developers out there. Is this something you’ve tried before? Are you planning to try it now? Leave a comment below or get in touch on Twitter. If there’s enough demand I’d like to take this idea further with 10-20 devices connected to Pi executing a lot of tests in parallel – if you’d be interested in reading about this then let us know.