在不同的官方Android网站上,有关于如何设置Espresso测试的不同信息:
1)https://developer.android.com/training/testing/ui-testing/espresso-testing
dependencies {
// Other dependencies ...
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
2)https://developer.android.com/studio/test/
dependencies {
// Required for local unit tests (JUnit 4 framework)
testCompile 'junit:junit:4.12'
// Required for instrumented tests
androidTestCompile 'com.android.support:support-annotations:24.0.0'
androidTestCompile 'com.android.support.test:runner:0.5'
}
3)https://developer.android.com/training/testing/espresso/setup
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
对于某些配置,我遇到了库冲突((2)解释说这是因为依赖关系需要相同的其他依赖但具有不同的版本)。
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
}
可能没帮助。
对于某些配置,我在导入android.support.test.rule.ActivityTestRule
答案 0 :(得分:0)
没有。 3似乎有效,有和没有exclude-part:
dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
}
对于较旧的espresso版本,例如2.2.2
,似乎不需要android.support.test.rule.ActivityTestRule
导入的单独依赖项。
答案 1 :(得分:0)
Espresso是一种仪器测试。它们放在与单元测试不同的文件夹中。它们保存在androidTest / java包中。因此,在使用依赖项时请记住这一点。对于仪器测试,您需要使用
androidTestImplementation
VS
testImplementation
假设您的Espresso测试类位于app-> src-> androidTest-> java位置,这应该可行:
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
答案 2 :(得分:0)
对于可能会想要这个的人来说,这是我的build.gradle
设置,其中包括Cucumber + Espresso + Barista:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.lomza.uitestsapp"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testApplicationId "com.lomza.uitestsapp.tests"
testInstrumentationRunner "com.lomza.uitestsapp.tests.GroceriesAppAndroidTestRunner"
}
sourceSets {
androidTest {
assets {
assets.srcDirs = ['src/androidTest/assets']
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation "io.cucumber:cucumber-android:4.4.1"
androidTestImplementation('com.schibsted.spain:barista:3.3.0') {
exclude group: 'org.jetbrains.kotlin'
}
}
检查我的整个tutorial,以查看其运作情况。