无法解析符号'ActivityTestRule'

时间:2018-05-30 03:31:10

标签: android android-espresso

我学会使用espresso来测试我的应用,但ActivityTestRule总是无法解决。这是我的app / build.gradle配置,我确信我把测试类放在src / androidTest。

非常感谢您的帮助!!

enter image description here

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'
}

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;,然后清理并重建您的应用。