Android test sharding on cloud virtual devices

Ellinor Kwok
Feb 6, 2017 · 3 min read
Image for post
Image for post

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:

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

Image for post
Image for post

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

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

Image for post
Image for post

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

Image for post
Image for post

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!

Genymobile

We help enterprises build their future with Android We’re…

Ellinor Kwok

Written by

Presales, Technical Partnership Manager at Genymobile

Genymobile

We help enterprises build their future with Android We’re the team behind @Genymotion, the most complete Android emulation platform. Now available in the cloud with powerful testing and collaboration capabilities 💪☁️ ️More at genymotion.com/cloud

Ellinor Kwok

Written by

Presales, Technical Partnership Manager at Genymobile

Genymobile

We help enterprises build their future with Android We’re the team behind @Genymotion, the most complete Android emulation platform. Now available in the cloud with powerful testing and collaboration capabilities 💪☁️ ️More at genymotion.com/cloud

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store