【错误记录】Android 单元测试报错 ( ExampleUnitTest.kt: (3, 12): Unresolved reference: junit / Test / assertEqu )

2023-03-30 15:48:01 浏览数 (1)

文章目录

  • 一、报错信息
  • 二、解决方案

一、报错信息


Android 中配置了单元测试 , 执行

代码语言:javascript复制
gradlew :app:testDebugUnitTest

命令 , 进行单元测试 , 报如下 错误 :

代码语言:javascript复制
Y:02_WorkSpace01_ASSVG>gradlew :app:testDebugUnitTest

> Task :app:compileDebugUnitTestKotlin FAILED
e: Y:02_WorkSpace01_ASSVGappsrctestjavakimhslsvgExampleUnitTest.kt: (3, 12): Unresolved reference: junit
e: Y:02_WorkSpace01_ASSVGappsrctestjavakimhslsvgExampleUnitTest.kt: (5, 12): Unresolved reference: junit
e: Y:02_WorkSpace01_ASSVGappsrctestjavakimhslsvgExampleUnitTest.kt: (13, 6): Unresolved reference: Test
e: Y:02_WorkSpace01_ASSVGappsrctestjavakimhslsvgExampleUnitTest.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 中配置如下测试相关依赖 :

代码语言:javascript复制
dependencies { 
    testImplementation 'junit:junit:4. '
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

配置完成后测试通过 :

0 人点赞