一、报错信息
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'
}
配置完成后测试通过 :