Note
This article is a reproduction of a medium article: Android test sharding on cloud virtual devices by Ellinor Kwok.
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 SaaS (Cloud) and Spoon come into play
Genymotion SaaS (Cloud) allows you to access live Android virtual devices from anywhere (if you don’t have Genymotion SaaS yet, well it’s never too late).
In this post we’re going to see how to perform Android test sharding with Genymotion SaaS 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
- First things first, head up to your build.gradle file
- Edit the dependency block as below (this will add Spoon and Genymotion dependencies)
- Apply the plugins by adding apply
- Add Spoon’s configuration
- Same for Genymotion’s configuration
NB: This will launch the Gradle task only when Genymotion SaaS virtual devices are already started.
- Choose which Genymotion SaaS 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 SaaS 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 SaaS 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.