Created
November 2, 2019 05:29
-
-
Save kartikayx/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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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