CarsonJc
CarsonJc

Reputation: 93

Can't resolve symbol 'ActivityTestRule'

I'm learn to use espresso to test my app, but ActivityTestRule always can't be resolved. Here is my app/build.gradle config, and I'm sure that I put test classes at src/androidTest.

Many thanks for help!!

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

Upvotes: 9

Views: 6996

Answers (2)

Sagar
Sagar

Reputation: 24917

Add import android.support.test.rule.ActivityTestRule; in your imports and then clean and rebuild your app.

Upvotes: 0

GParekar
GParekar

Reputation: 1219

I hope this will work for you.

Use

androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

Instead

androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestCompile 'com.android.support.test:runner:1.0.2'

Upvotes: 11

Related Questions