JUnit 本地测试 - '未解决的参考:测试'

Ada*_*itz 4 junit android junit4 kotlin android-testing

预期的

导入库,比如androidx.test:core:1.2.0androidx.test.ext:truth:1.2.0com.google.truth:truth:0.44,等进入当地的JUnit命名测试类ExampleUnitTest.kt

观察到的

错误

未解决的参考:测试

执行

示例UnitTest.kt

import androidx.test.core.app.ApplicationProvider.getApplicationContext
import com.google.common.truth.Truth.assertThat
Run Code Online (Sandbox Code Playgroud)

Ada*_*itz 20

解决方案

这似乎是Android 测试代码实验室示例应用中记录的问题。

在 Codelab 示例build.gradle 中,这被称为已知问题。

// Once https://issuetracker.google.com/127986458 is fixed this can be testImplementation
implementation "androidx.test:core:$androidXTestCoreVersion"
Run Code Online (Sandbox Code Playgroud)

我重构了我的应用程序的依赖项testImplementation而不是androidTestImplementation.

testImplementation 'androidx.test:core:1.2.0'
testImplementation 'androidx.test.ext:truth:1.2.0'
testImplementation 'com.google.truth:truth:0.44'
Run Code Online (Sandbox Code Playgroud)

-应更新Google 文档为 AndroidX 测试设置项目以反映此问题,因为它当前指示开发人员使用androidTestImplementation. 我已经提交了一个文档问题来解决这个问题。