我已經有一堆Roboelectric測試。我想添加最近推出的Espresso 2.0。在Android項目中使用Espresso 2.0 + Roboelectric
Roboelectric推出了deckard-gradle template project來解決使用Roboelectric和Espresso的問題。但解決方案是現在已棄用的Espresso 1.1。
這是當我有Roboelectric以及以下Espresso 2.0 instruction才能使用咖啡2.0我的build.gradle文件的一部分:
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和咖啡測試。我很欣賞任何建議。
附錄:
to run roboelectric test : gradlew test
to run espresso: gradlew connectedAndroidTest
我不是在儀器測試方面的專家。但是我認爲你甚至可以從工作室對Espresso進行單獨測試。要做同樣的Robolectric你應該另一個gradle插件(我不使用它,所以不能肯定地說) – 2015-01-22 09:11:06