问题描述
将诸如androidx.test:core:1.2.0
,androidx.test.ext:truth:1.2.0
,com.google.truth:truth:0.44
之类的库导入到名为 ExampleUnitTest.kt 的本地JUnit 测试类中.
Importing libraries such as androidx.test:core:1.2.0
, androidx.test.ext:truth:1.2.0
, com.google.truth:truth:0.44
, and etc. into a local JUnit test class named ExampleUnitTest.kt.
实施
ExampleUnitTest.kt
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import com.google.common.truth.Truth.assertThat
推荐答案
解决方案
这似乎是 Android测试Codelab示例应用中记录的问题.
Solution
This appears to be an issue documented in the Android Testing Codelab sample app.
在Codelab示例 build.gradle 中,这被称为已知问题.
Within the Codelab sample build.gradle this is referred to as a known issue.
// Once https://issuetracker.google.com/127986458 is fixed this can be testImplementation
implementation "androidx.test:core:$androidXTestCoreVersion"
我将应用程序的依赖关系重构为testImplementation
而不是androidTestImplementation
.
I refactored my app's dependency to testImplementation
instead of androidTestImplementation
.
testImplementation 'androidx.test:core:1.2.0'
testImplementation 'androidx.test.ext:truth:1.2.0'
testImplementation 'com.google.truth:truth:0.44'
注意-Google文档 AndroidX Test的设置项目,以反映此问题,因为它目前指示开发人员使用androidTestImplementation
.我已提交文档问题来解决此问题.
Note - The Google documentation Set up project for AndroidX Test should be updated to reflect this issue as it currently instructs the developer to use androidTestImplementation
. I have filed a documentation issue to resolve this.
这篇关于JUnit本地测试-'未解决的参考:测试'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!