我希望能够为我的Android项目提供两个(或多个)测试任务,其中差异是要包含/排除的一组不同的Junit类别.
使用gradle java插件,我可以做类似的事情
task testFast(type: Test) {
useJUnit {
includeCategories 'foo.Fast'
excludeCategories 'foo.Slow'
}
}
task testSlow(type: Test) {
useJUnit {
includeCategories 'foo.Slow'
excludeCategories 'foo.Fast'
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果使用android插件,我必须将testOptions添加到android闭包中以包含/排除,
android {
...
testOptions {
unitTests.all {
useJUnit {
excludeCategories foo.Slow'
}
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
但当然这适用于所有构建变体的所有测试任务.
有没有办法创建使用相同构建变体的任务,但是对不同类别执行测试?