Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未解析的引用:匹配器_Android_Junit_Kotlin_Hamcrest - Fatal编程技术网

Android 未解析的引用:匹配器

Android 未解析的引用:匹配器,android,junit,kotlin,hamcrest,Android,Junit,Kotlin,Hamcrest,导入org.hamcrest.Matchers时无法运行单元测试,因为我需要lessThan()。在使用greaterThanmatcher而不是单元测试时,我的工具测试可以正确编译 代码: Gradle日志: 删除第二行会使项目编译并运行测试。我也遇到了同样的问题。我所发现的是,我只是在仪器化测试中遇到了这个问题。非仪器化测试能够导入并正常运行 对我来说,解决这个问题的方法是在我的依赖项中添加androidTestImplementation'com.android.support.test.

导入
org.hamcrest.Matchers
时无法运行单元测试,因为我需要
lessThan()
。在使用
greaterThan
matcher而不是单元测试时,我的工具测试可以正确编译

代码:

Gradle日志:


删除第二行会使项目编译并运行测试。

我也遇到了同样的问题。我所发现的是,我只是在仪器化测试中遇到了这个问题。非仪器化测试能够导入并正常运行

对我来说,解决这个问题的方法是在我的依赖项中添加
androidTestImplementation'com.android.support.test.espresso:espresso core:3.0.2'


我认为这是没有必要的,因为我的测试没有明确使用浓缩咖啡。事实证明是的,原因超出了我的理解。

在我的例子中,我在运行任务compileTestKotlin时收到了一个编译器错误“Unresolved reference:Matchers”。事实证明,我已经将hamcrest依赖项声明为testRuntimeOnly。将其更改为测试实施修复了该问题

testImplementation("org.hamcrest:hamcrest:2.2")

查看文档很有趣。

我有
androidTestImplementation'androidx.test.espresso:espresso core:3.1.1'
,但错误仍然存在
testImplementation("org.hamcrest:hamcrest:2.2")