@UiThreadTest 未解决的参考

@UiThreadTest Unresolved Reference

我需要在 UI 线程上对 运行 进行测试,所以我想使用 UiThreadTest 注释,但它没有解析该注释。我猜我必须在 gradle 文件中包含一个依赖项,但我终究无法弄清楚它是什么。

@Test
@UiThreadTest
fun insertMultipleDelete() {

我的模块的 build.gradle 依赖项:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0'

    def nav_version = "2.3.3"
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

    def room_version = "2.2.6"
    implementation "androidx.room:room-runtime:$room_version"
    implementation "androidx.room:room-ktx:$room_version"
    kapt "androidx.room:room-compiler:$room_version"

    testImplementation "androidx.room:room-testing:$room_version"
    testImplementation 'androidx.test:core:1.3.0'
    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

我需要做什么才能解决?

明白了,您必须在 gradle 文件中包含 androidTestImplementation 'androidx.test:rules:1.3.0'

在某个德国网站上找到它,感谢您提供出色的文档 Google。