我学会使用espresso来测试我的应用,但ActivityTestRule
总是无法解决。这是我的app / build.gradle配置,我确信我把测试类放在src / androidTest。
非常感谢您的帮助!!
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.android.teatime"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:design:27.1.1'
compile 'com.android.support:support-annotations:27.1.1'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
// Testing-only dependencies
androidTestCompile 'com.android.support:support-annotations:27.1.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestCompile 'com.android.support.test:runner:1.0.2'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:3.0.2'
androidTestCompile 'com.android.support.test:rules:1.0.2'
}
答案 0 :(得分:11)
我希望这对你有用。
使用
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
相反
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestCompile 'com.android.support.test:runner:1.0.2'
答案 1 :(得分:1)
在导入中添加import android.support.test.rule.ActivityTestRule;
,然后清理并重建您的应用。