当我导入 org.hamcrest.Matchers
时,我无法运行单元测试,因为我需要 lessThan()
。我的仪器测试在使用 greaterThan
匹配器而不是单元测试时编译正确
代码:
import org.hamcrest.CoreMatchers.*
import org.hamcrest.Matchers.lessThan
import org.junit.Assert.assertThat
import org.junit.Test
import java.util.*
Gradle 日志:https://pastebin.com/ibgzzrg1
删除第二行使项目编译并运行测试。
最佳答案
在我的例子中,我在运行 Task :compileTestKotlin 时收到编译器错误“Unresolved reference: Matchers”。事实证明,我已将 hamcrest 依赖项声明为 testRuntimeOnly。将其更改为 testImplementation 解决了这个问题。
testImplementation("org.hamcrest:hamcrest:2.2")
查看文档很有趣here .
关于android - Unresolved reference : Matchers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52677128/