Skip to content

Instantly share code, notes, and snippets.

@alphaguy4
Created November 2, 2019 05:29
Show Gist options
  • Save alphaguy4/43282ef93392eccb16cd6cb42c28ad38 to your computer and use it in GitHub Desktop.
Save alphaguy4/43282ef93392eccb16cd6cb42c28ad38 to your computer and use it in GitHub Desktop.
This script enables an android project to run it's intrumentation test parallely on multiple emulators by sharding using spoon framework.
/*
* Include this file into main build.gradle of the project.
* Replace the task connectedPlaystoreDebugAndroidTest with
* parallelInstrumentationRun to run test in parallel
*/
configurations.create('spoonTest').transitive(false)
dependencies {
spoonTest group:'com.squareup.spoon', name:'spoon-runner', version:'1.7.1', classifier: 'jar-with-dependencies', ext: 'jar'
}
task parallelInstrumentationRun {
dependsOn assembleAndroidTest
doLast {
// Pulling out spoon-runner.jar from resolvedArtificats and saving it in build directory under spoontestjar foldeer
configurations.spoonTest.resolvedConfiguration.resolvedArtifacts.each { artifact ->
copy {
from artifact.file
into "${buildDir}/spoontestjar"
rename("spoon-runner-(.*).jar", "spoonTestRunner.jar")
}
}
def sdkDir = android.sdkDirectory
List<String> argument = ["${buildDir}/spoontestjar/spoonTestRunner.jar", /* path to spoon-runner-jar */
"--apk", "$buildDir/outputs/apk/playstore/debug/securemail-playstore-debug.apk", /* path to apk */
"--test-apk", "$buildDir/outputs/apk/androidTest/playstore/debug/securemail-playstore-debug-androidTest.apk", /* path to test apk */
"--sdk" , "$sdkDir", /* path to android sdk */
"--output", "$buildDir/reports/spoonTestResults", /* define path for test results */
"--coverage", "true", /* Enable merging of coverage file pulled from devices running test*/
"--shard", /* Enable auto sharding: splitting testcases automatically between all connected emulators */
"--debug", /*print test running logs to console*/
"--fail-on-failure"].toList() /*fail task if any test fails*/
javaexec {
main = "-jar"
args = argument
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment