微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在androidx上解析符号“ ActivityTestRule”

如何解决无法在androidx上解析符号“ ActivityTestRule”

我正在尝试测试我的Activity,但是无法导入ActivityTestRule。

我的gradle文件

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
// Add the Firebase Crashlytics plugin.
apply plugin: 'com.google.firebase.crashlytics'
android {
    compileSdkVersion 30
    defaultConfig {
        applicationId "com.example”
        minSdkVersion 23
        targetSdkVersion 30
        versionCode 3
        versionName "1.3"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    packagingOptions {
        exclude 'meta-inf/DEPENDENCIES'
        exclude 'meta-inf/INDEX.LIST'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
        }
        debug {
            testCoverageEnabled true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
}

dependencies {
    implementation filetree(dir: 'libs',include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.3'
    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    implementation 'com.google.android.material:material:1.2.1'
    androidTestImplementation 'org.junit.jupiter:junit-jupiter:5.7.0'
    testImplementation 'org.objenesis:objenesis:2.6'
    // Espresso Core library
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// AndroidJUnitRunner and JUnit Rules
    androidTestImplementation 'androidx.test:runner:1.3.0'
    androidTestImplementation 'androidx.test:rules:1.3.0'
    // Optional -- UI testing with UI Automator
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
    
}

修改 我也尝试过ActivityScenarioRule。相同的问题,无法解析符号ActivityScenarioRule

public ActivityScenarioRule rule = new ActivityScenarioRule<>(LoginActivity.class);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。