首页 > 解决方案 > 类 Matcher 不需要类型参数

问题描述

我正在尝试为浓缩咖啡测试创建一个自定义匹配器。到目前为止,我的代码是:

private fun withCrossedOutText(): Matcher<View> {
    return object :  BoundedMatcher<View, TextView>(TextView::class.java) {
        override fun matchesSafely(item: TextView?): Boolean {
            // Code
        }

        override fun describeTo(description: org.hamcrest.Description?) {
            // Code
        }
    }
}

这在第一行给出了一个错误说

类 Matcher 不需要类型参数

我试过删除<View>,但这会产生更多问题。

标签: androidkotlinandroid-espresso

解决方案


问题是导入了错误的 Matcher 包。我最初使用的是正则表达式匹配器,但是当我使用 Hamcrest Matcher 时,问题就消失了。


推荐阅读