在不同的官方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'- Even excluding with androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2', { exclude group: 'com.android.support', module: 'support-annotations' }可能帮不上忙。
android.support.test.rule.ActivityTestRule时出错发布于 2018-05-04 16:38:49
第三条似乎行得通,不管排除与否-部分:
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导入不需要单独的依赖项。
发布于 2018-06-03 17:23:46
意式咖啡是一种仪器测试。这些被放置在一个与单元测试不同的文件夹中。它们被保存在新的androidTest/java超级包中。因此,在使用依赖关系时要记住这一点。对于您需要使用的仪表测试
androidTestImplementationvs
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'发布于 2020-04-23 08:35:54
对于可能会寻找这个的人来说,这是我用Cucumber + Espresso +Barista安装的build.gradle:
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'
}
}检查一下我的整个教程,看看它在起作用。
https://stackoverflow.com/questions/50179597
复制相似问题