如何测试 val/var 是否属于预期类型?
在 Kotlin 测试中我是否缺少某些东西,例如:
value shouldBe instanceOf<ExpectedType>()
以下是我的实现方式:
inline fun <reified T> instanceOf(): Matcher<Any> {
return object : Matcher<Any> {
override fun test(value: Any) =
Result(value is T, "Expected an instance of type: ${T::class} \n Got: ${value::class}", "")
}
}