Android:使用junit 4.13时无法解析的参考 [英] Android: Unresolved reference when using junit 4.13

查看:212
本文介绍了Android:使用junit 4.13时无法解析的参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在gradle依赖项中将junit版本更新为4.13之后,在我的代码中使用时,junit包下的类和批注(例如Assert@Test等)显示为红色.皮棉检查说:

After updating junit version to 4.13 in gradle dependencies, classes and annotations like Assert, @Test, etc. under the junit package are displayed as red when used in my code. Lint check says:

Unresolved reference: <any junit class>

但是,当我构建并运行测试时,它就可以构建并运行.

However, when I build and run my tests, it will build and run just fine.

我尝试过:

  • 重新启动Android Studio
  • 使缓存无效并重新启动
  • 清理并重建项目
  • 添加了testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
  • restarting Android Studio
  • Invalidate caches and restart
  • Clean and rebuild project
  • added testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"

有效的方法是将junit降级为4.12.如何在不降级的情况下摆脱此皮棉错误?

What works is downgrading junit to 4.12. How to get rid of this lint error, without downgrading version?

更新:

  • 当我检查ALT + ENTER选项并选择Inspection 'Unresolved reference, in wrong test scope' options> Suppress 'IncorrectScope' for file <name of file>时,它将消除该特定文件的这些皮棉错误.我仍然喜欢不使用Suppress来解决此问题.
  • 根据此问题,看来此错误尚未修复.现在我降级到4.12.
  • 从依赖项中删除浓缩咖啡和热流道也可以解决此问题.
  • When I check ALT + ENTER options and select Inspection 'Unresolved reference, in wrong test scope' options > Suppress 'IncorrectScope' for file <name of file>, it gets rid of these lint errors for that particular file. I still like to solve this problem without using Suppress though.
  • According to this issue, it looks like this bug is not fixed yet. For now I'm downgrading to 4.12.
  • Removing both espresso and runner from dependencies also fixes the problem.

推荐答案

只需将以下内容添加到您的build.gradle(App)文件中:

Just add the following to your build.gradle (App) file:

configurations.all {
    resolutionStrategy.force "junit:junit:$junit_version"
}

dependencies {
...
}

这篇关于Android:使用junit 4.13时无法解析的参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆