Din*_*esh 5 android automated-tests unit-testing android-gradle-plugin android-instrumentation
我的 android 测试包上有大约 25 个测试。我有一些要在集成过程中运行的测试,以及一些作为普通仪器测试运行的测试。我正在尝试使用 Gradle 任务调用集成测试,但仪器测试似乎不可能。我已经检查过单元测试,有可能是这样的——
task integrationTest(
type: Test,
description: 'Run integration tests only. Pass in \'-Pintegration=true\'',
dependsOn: ['testDebugUnitTest', 'clean'] ) {
//Here for task completion, not actually used since sub task of testDebugUnitTest
testClassesDir = file("src/integrationTest/java/");
classpath = files("$System.env.ANDROID_HOME/sources/android-18")
//
//Turn on integration testing when argument exists and is true
//
if (project.hasProperty('integration')) {
println integration
if (integration == 'true') {
integrationTests = true
}
}
}
Run Code Online (Sandbox Code Playgroud)
并做这样的事情
testOptions {
unitTests.all {
useJUnit()
if (integrationTests.toBoolean()) {
println "Integration Tests Only for " + it.name
options {
excludeCategories 'com.example.reactivemvp.categories.UnitTest'
}
} else {
println "Unit Tests Only for " + it.name
options {
excludeCategories 'com.example.reactivemvp.categories.IntegrationTest'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经看到 testOptions 只适用于单元测试而不适用于仪器测试。我发现了访问仪器测试的方法是什么-
testVariants.all { variant ->
if(connectedInstrumentTest.name)
variant.connectedInstrumentTest.doFirst {
println "This will be executed right after our connectedInstrumentTest!"
println "The name of the test type: $connectedInstrumentTest.name"
if (intergrationTests == true) {
exclude '**/*androidTest.functionalTests*'
}
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
Could not find method exclude() for arguments [**/*androidTest.functionalTests*] on task ':app:connectedAndroidTest'
有没有办法通过一些 Gradle 任务只调用一部分仪器测试?
| 归档时间: |
|
| 查看次数: |
214 次 |
| 最近记录: |