在 gradle 依赖中更新 junit 版本至 4.13 后,在我的代码中使用 junit 包下的类和注解,如 Assert、@Test 等时会显示为红色。 Lint 检查提示:
Unresolved reference: <any junit class>
然而,在构建并运行我的测试时,它可以正常构建和运行。
我尝试过:
- 重新启动Android Studio
- 无效的高速缓存并重启
- 清理并重新构建项目
- 添加
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来解决这个问题。 - 根据这个问题,看起来这个bug还没有被修复。现在我降级到4.12。
- 从依赖项中删除espresso和runner也可以解决问题。