I'd like to be able to have two (or multiple) test tasks for my Android project, where the difference is a different set of Junit Categories to include/exclude.
Using the gradle java plugin, I can do something like
task testFast(type: Test) {
useJUnit {
includeCategories 'foo.Fast'
excludeCategories 'foo.Slow'
}
}
task testSlow(type: Test) {
useJUnit {
includeCategories 'foo.Slow'
excludeCategories 'foo.Fast'
}
}
However, if using the android plugin, I have to add testOptions to the android closure to include/exclude,
android {
...
testOptions {
unitTests.all {
useJUnit {
excludeCategories foo.Slow'
}
}
}
...
}
but of course that applies to all test tasks for all build variants.
Is there a way to create tasks that use the same build variant, but execute tests on different categories?
Best I've come up with is to use a gradle property from the command line:
testOptions {
unitTests.all {
useJUnit {
if (project.hasProperty('testCategory') && testCategory == "Slow") {
includeCategories 'foo.Slow'
} else {
excludeCategories 'foo.Slow'
}
}
}
}
and use
gradlew -PtestCategory=Slow test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With