用gradle分开整合测试任务 [英] Separate integration test task on gradle with android
问题描述
我想要运行默认测试运行中排除路径中的集成字的测试,但我想在一个单独的任务中将它们一起运行。目前我有一个基本的测试配置:
sourceSets {
androidTest.setRoot('src / test')
integrationTest.setRoot('src / test')
}
...
androidTestCompile'junit:junit:4.11'
androidTestCompile'com.jayway.android.robotium:robotium-solo:5.1'
androidTestCompile文件('libs / android-junit-report-1.5.8.jar')
androidTestCompile'com.squareup :fest-android:1.0.8'
androidTestCompile'org.robolectric:robolectric:2.3'
integrationTestCompile'junit:junit:4.11'
integrationTestCompile'com.jayway.android .robotium:robotium-solo:5.1'
integrationTestCompile文件('libs / android-junit-report-1.5.8.jar')
integrationTestCompile'com.squareup:fest-android:1.0.8'
integrationTestCompile'org.robolectric:robolectric:2.3'
...
androidTest {
include'** / * Test.class'
排除'** / espresso / ** / *。class
exclude'** / integration / **'
}
任务集成测试(类型:测试){
包含'** / integration / **'$
$ p
$ b 这会导致在同步AS中的gradle时出错:
警告:project':ProjectName':无法解析所有内容根目录
详细信息:java.lang.NullPointerException:null
但是如果我删除了integrationTest任务,它不会发生。
错误:无法确定任务':ProjectName:integrationTest'的依赖关系。
必须在任务中或通过方法参数指定基础目录!
解决方案它并不完全明显,但是这个错误是由于未在任务定义中定义 testClassesDir
造成的。
task integrationTest类型:Test){
include'** / integration / **'
testClassesDir = file('build / intermediates / classes')
}
类似的内容在 Gradle用户指南,但它并未完全转换为Android插件。我还没有制定出所有的细节,但我会更新这个答案,因为我明白了。
I want to run tests that have the 'integration' word in the path to be excluded with the default test run, but I want to run them all together in a separate task. Currently I have a basic test configuration:
sourceSets {
androidTest.setRoot('src/test')
integrationTest.setRoot('src/test')
}
...
androidTestCompile 'junit:junit:4.11'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.1'
androidTestCompile files('libs/android-junit-report-1.5.8.jar')
androidTestCompile 'com.squareup:fest-android:1.0.8'
androidTestCompile 'org.robolectric:robolectric:2.3'
integrationTestCompile 'junit:junit:4.11'
integrationTestCompile 'com.jayway.android.robotium:robotium-solo:5.1'
integrationTestCompile files('libs/android-junit-report-1.5.8.jar')
integrationTestCompile 'com.squareup:fest-android:1.0.8'
integrationTestCompile 'org.robolectric:robolectric:2.3'
...
androidTest {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
exclude '**/integration/**'
}
task integrationTest(type: Test) {
include '**/integration/**'
}
This causes an error while syncing gradle in AS:
Warning: project ':ProjectName': Unable to resolve all content root directories
Details: java.lang.NullPointerException: null
but if I remove the integrationTest task it doesn't occur. Also with the task present I am able to run the 'integrationTest' task but this causes another error:
Error:Could not determine the dependencies of task ':ProjectName:integrationTest'.
A base directory must be specified in the task or via a method argument!
解决方案 It isn't entirely obvious, but this error is caused by not defining testClassesDir
in your task definition.
task integrationTest(type: Test) {
include '**/integration/**'
testClassesDir = file('build/intermediates/classes')
}
Something similar is described in the Gradle User Guide for the Java plugin, but it doesn't entirely translate to the Android plugin. I haven't worked out all of the particulars just yet, but I will update this answer as I figure it out.
这篇关于用gradle分开整合测试任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!