在gradle这个依赖性,类和类似注解更新JUnit版本到4.13之后Assert,@TestJUnit包下等在我的代码中使用时显示为红色。棉绒检查 说:
Unresolved reference: <any junit class>
Run Code Online (Sandbox Code Playgroud)
但是,当我构建和运行我的测试时,它会构建和运行得很好。
我试过了:
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"有效的是将 junit 降级到 4.12。如何在不降级版本的情况下摆脱这个 lint 错误?
更新:
ALT + ENTER选项并选择Inspection 'Unresolved reference, in wrong test scope' options> 时Suppress 'IncorrectScope' for file <name of file>,它会消除该特定文件的这些 lint 错误。我仍然喜欢在不使用 Suppress 的情况下解决这个问题。导入库,比如androidx.test:core:1.2.0,androidx.test.ext:truth:1.2.0,com.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)