Issue
I have three devices defined in the genymotion section of my build.gradle
:
apply plugin: "genymotion"
genymotion {
devices {
"Google Nexus 5 - 5.1.0 - API 22 - 1080x1920" {
template String.valueOf(it)
deleteWhenFinish false
}
"Google Nexus 7 - 4.2.2 - API 17 - 800x1280" {
template String.valueOf(it)
deleteWhenFinish false
}
"Google Nexus 9 - 5.1.0 - API 22 - 2048x1536" {
template String.valueOf(it)
deleteWhenFinish false
}
}
config {
genymotionPath = "/Applications/Genymotion.app/Contents/MacOS/"
taskLaunch = "connectedCheck"
}
}
connectedCheck.dependsOn genymotionLaunch
connectedCheck.mustRunAfter genymotionLaunch
genymotionFinish.mustRunAfter connectedCheck
When I run ./gradlew connectedCheck
all three are launched and tests ran on them simultaneously. If I wanted to add all devices that I'd like to test my app on, that list would grow to 20+ devices which my machine would not cope with. Therefore, I need a way to launch these tests in batches, of say 3. Is there a way to do this?
Solution
This can be achieved by creating productFlavors just for tests:
productFlavors {
dev; // dev/smoke tests
api18; api19; api21; // all api levels tests
}
These will produce separate test tasks that can be launched separately or in succession:
task allConnectedAndroidTests(type: GradleBuild) {
tasks = [
'connectedApi18DebugAndroidTest',
'connectedApi19DebugAndroidTest',
'connectedApi21DebugAndroidTest'
]
}
Simply assign a buildFlavor to your one, or more devices:
"Google Nexus 5 - 5.1.0 - API 22 - 1080x1920" {
template String.valueOf(it)
productFlavors "api21"
}
"Google Nexus 7 - 4.2.2 - API 17 - 800x1280" {
template String.valueOf(it)
productFlavors "api18"
}
And when you launch one of the assigned launch tasks, only the assigned devices will be launched and have the tests ran on them. For example:
./gradlew allConnectedAndroidTests
...
<...>genymotionLaunchConnectedApi18DebugAndroidTest
<...>connectedApi18DebugAndroidTest
<...>genymotionFinishConnectedApi18DebugAndroidTest
...
<...>genymotionLaunchConnectedApi19DebugAndroidTest
<...>connectedApi19DebugAndroidTest
<...>genymotionFinishConnectedApi19DebugAndroidTest
...
<...>genymotionLaunchConnectedApi21DebugAndroidTest
<...>connectedApi21DebugAndroidTest
<...>genymotionFinishConnectedApi21DebugAndroidTest
...
BUILD SUCCESSFUL
Full source of this example: https://github.com/tomaszrykala/Genymotion-productFlavors/blob/master/app/build.gradle
Answered By - TomaszRykala
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.