Espresso测试的正确依存关系是什么? [英] What are the correct dependencies for Espresso tests?
问题描述
在不同的Android官方网站上,有关如何设置Espresso测试的信息不同:
On different official Android sites there is different information on how to set up Espresso tests:
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)解释这是由于依赖关系需要相同的其他依赖关系但具有不同的版本).
With some configurations I get library conflicts ((2) explains that this is due to dependencies requiring the same other dependency but with different versions).
- 甚至不包括
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2', { exclude group: 'com.android.support', module: 'support-annotations' }
可能无济于事.androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2', { exclude group: 'com.android.support', module: 'support-annotations' }
might not help.在某些配置下,导入
android.support.test.rule.ActivityTestRule
推荐答案
对于可能会寻求此解决方案的人,这是我的
build.gradle
设置,其中包含Cucumber + Espresso + Barista:For somebody who might look for this, this is my
build.gradle
setup with 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' } }
检查我的整个教程以查看实际效果.
Check my whole tutorial to see it in action.
这篇关于Espresso测试的正确依存关系是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!