我已经进行了一堆 Roboelectric 测试。我想添加 Espresso 2.0这是最近推出的。
Roboelectric 介绍 deckard-gradle template project解决 Roboelectric 和 Espresso 一起使用的问题。但解决方案适用于现在已弃用的 Espresso 1.1。
这是我的 build.gradle 文件的一部分,以便在我拥有 Roboelectric 以及以下 Espresso 2.0 instruction 后使用 Espresso 2.0 :
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'org.robolectric:robolectric-gradle-plugin:0.13.2'
}
}
apply plugin: 'com.android.application'
apply plugin: 'robolectric'
android {
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
}
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
versionCode 1
versionName '1.0'
minSdkVersion 9
targetSdkVersion 21
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
robolectric {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
}
dependencies {
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile('junit:junit:4.11') {
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'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'support-v4'
}
}
但我无法单独运行 Roboelectric 和 Espresso 测试。感谢您提出任何建议。
附录:
to run roboelectric test : gradlew test
to run espresso: gradlew connectedAndroidTest
最佳答案
试试这个 android 入门项目: https://github.com/freezy/android-seed
它有很多features :
- 在 Android Studio 中很好地加载
- Robolectric 测试在 IDE 中运行并可调试(用于单元测试)
- Espresso 测试在 IDE 中工作并可调试(用于功能测试)
- 最新的 Lollipop 兼容库可供使用
- 启用测试覆盖率
关于android - 在 Android 项目中使用 Espresso 2.0 + Roboelectric,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28066216/