Espresso 测试依赖项

Espresso testing dependencies

    defaultConfig {
    multiDexEnabled true
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

    androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
// Optional -- Hamcrest library
androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
// Optional -- UI testing with Espresso
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
// Optional -- UI testing with UI Automator
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'

我正在尝试编写仪器测试。我正在尝试在 androidTest/java 下创建测试 class 但它显示所有 android.test class 的错误,即使我已经在 gradle.[=13 中添加了所有依赖项=]

检查您正在测试的构建变体,确保它不是发行版。

更改您的 Gradle 文件

android {
    ...
    testBuildType "debug"
}

现在将您当前的构建变体更改为调试,然后尝试编译项目。

供google参考检查下方link

https://developer.android.com/studio/test