Android test sharding on cloud virtual devices

Ellinor Kwok
Genymobile
Published in
3 min readFeb 6, 2017

Developing high quality applications requires lots of testing. Sometimes hundreds or thousands of automated tests need to be run continuously before a pull request gets validated. If the tests take too much time this can slow down a project velocity. Just imagine 100 tests taking 30 minutes to complete on one single device.

What if you could split these tests on several devices to speed up your tests? This is test sharding. Say we break up the 100 tests we mentioned above and run them on 2 devices (50 tests each), the test session will theoretically only last 15 minutes instead of 30. Sounds good right?

This is where Genymotion Cloud and Spoon come into play

Genymotion Cloud allows you to access live Android virtual devices from anywhere (if you don’t have Genymotion Cloud yet, well it’s never too late).

In this post we’re going to see how to perform Android test sharding with Genymotion Cloud and Spoon, the framework from Square that distributes instrumentation tests and displays the results within an HTML page. Spoon also provides auto-sharding, a feature that will split all your tests automatically across devices.

This tutorial will cover the use of Genymotion and Spoon Gradle plugin. It is also available in video:

Configure build.gradle

1. First things first, head up to your build.gradle file

2. Edit the dependency block as below (this will add Spoon and Genymotion dependencies)

3. Apply the plugins by adding apply

4. Add Spoon’s configuration

5. Same for Genymotion’s configuration

NB: This will launch the Gradle task only when Genymotion Cloud virtual devices are already started.

6. Choose which Genymotion Cloud virtual devices will be used for your tests

Run your tests

Only one command is needed for this step:

./gradlew spoonDebugAndroidTest

This will launch Genymotion Cloud virtual devices before instrumentation tests get launched. Cloud virtual devices will turn off automatically once tests are over.

Retrieve results

Test results are created by Spoon at ../build/spoon/debug/index.html

As you can see, the taxonomy is Genymotion + <device name>

For more details on a specific test, simply click on the device name.

Each device generates logs for each test, which can come pretty if you need to find the root cause of a bug.

Conclusion

Auto-sharding Android tests with Spoon on Genymotion Cloud virtual devices is actually pretty straightforward and will definitely save you time. So what we’ve got here is probably one of the best combos you can find around for Android automation testing.

Thank you for your time reading this post, hope you’d like it (this was my first). Feel free to let me know your thoughts in the comments section.

I’ve covered other ways to perform Android test sharding on cloud devices in Genymotion’s official blog. If you want to apply a strategy different than auto-sharding, there’s a lot you can get in Spoon’s documentation. Enjoy!

--

--

Ellinor Kwok
Genymobile

Presales, Technical Partnership Manager at Genymobile