错误记录Android 单元测试报错 ( ExampleUnitTest.kt: (3, 12): Unresolved reference: junit / Test / assertEqu )
Posted 韩曙亮
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了错误记录Android 单元测试报错 ( ExampleUnitTest.kt: (3, 12): Unresolved reference: junit / Test / assertEqu )相关的知识,希望对你有一定的参考价值。
文章目录
一、报错信息
android 中配置了单元测试 , 执行
gradlew :app:testDebugUnitTest
命令 , 进行单元测试 , 报如下 错误 :
Y:\\002_WorkSpace\\001_AS\\SVG>gradlew :app:testDebugUnitTest
> Task :app:compileDebugUnitTestKotlin FAILED
e: Y:\\002_WorkSpace\\001_AS\\SVG\\app\\src\\test\\java\\kim\\hsl\\svg\\ExampleUnitTest.kt: (3, 12): Unresolved reference: junit
e: Y:\\002_WorkSpace\\001_AS\\SVG\\app\\src\\test\\java\\kim\\hsl\\svg\\ExampleUnitTest.kt: (5, 12): Unresolved reference: junit
e: Y:\\002_WorkSpace\\001_AS\\SVG\\app\\src\\test\\java\\kim\\hsl\\svg\\ExampleUnitTest.kt: (13, 6): Unresolved reference: Test
e: Y:\\002_WorkSpace\\001_AS\\SVG\\app\\src\\test\\java\\kim\\hsl\\svg\\ExampleUnitTest.kt: (15, 9): Unresolved reference: assertEquals
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugUnitTestKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 5s
19 actionable tasks: 1 executed, 18 up-to-date
二、解决方案
在 build.gradle 中配置如下测试相关依赖 :
dependencies
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
配置完成后测试通过 :
以上是关于错误记录Android 单元测试报错 ( ExampleUnitTest.kt: (3, 12): Unresolved reference: junit / Test / assertEqu )的主要内容,如果未能解决你的问题,请参考以下文章
错误记录Android Studio 中生成测试覆盖率报告出错 ( ExampleInstrumentedTest > useAppContext[Pixel 2 - 9] FAILED )
错误记录Android Studio 编译时 lint 检查报错 ( WARNING: DSL element ‘android.dataBinding.enabled‘ is obsolet )
错误记录Android Studio 编译时 lint 检查报错 ( Could not resolve junit:junit:4.+. )
错误记录记录 Android 命令行执行 Java 程序中出现的错误 ( dx 打包 PC 可执行文件报错 | dalvik 命令执行 kotlin 编译的 dex 文件报错 )