Android 将设备仪器化测试添加到具有机器人分子测试的项目中
我有一个Android项目,它使用Robolectric进行测试。build.gradle的相关部分如下所示:Android 将设备仪器化测试添加到具有机器人分子测试的项目中,android,gradle,robolectric,robolectric-gradle-plugin,Android,Gradle,Robolectric,Robolectric Gradle Plugin,我有一个Android项目,它使用Robolectric进行测试。build.gradle的相关部分如下所示: apply plugin: 'robolectric' robolectric { include '**/*Test.class' } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile 'org.hamcrest:hamcrest-int
apply plugin: 'robolectric'
robolectric {
include '**/*Test.class'
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.12') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
androidTestCompile 'com.android.support:support-v4:21.0.3'
}
所有的机器人测试都在src/androidTest/java/my/package/*Test.java
中。这一切都非常有效。我可以作为普通Gradle构建的一部分运行测试,或者通过IntelliJ的JUnitGUI运行测试
现在我需要添加一些不能使用Robolectric的测试,需要在真正的Android设备上运行。考虑到我已经不得不使用
androidTest
变量进行机器人测试,我如何才能将我的仪器测试添加到此项目中,并且仍然允许机器人测试在没有设备的情况下运行?这是一种超过时的设置,我建议:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
//apply plugin: 'robolectric'
//robolectric {
// include '**/*Test.class'
//}
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
//apply plugin: 'robolectric'
//robolectric {
// include '**/*Test.class'
//}
test
文件夹androidTestCompile
更改为testCompile
/gradlew testDebugUnitTest
运行测试。您可以将仪器测试添加到androidTest
文件夹中
考虑将Robolectric升级到3.1
版本