我可以在 Kotlin 中使用 MockK 模拟通用(模板)私有方法吗?
Can I mock a generic (template) private method using MockK in Kotlin?
我想模拟以下功能:
private fun <T> updateItemInDb(id: Long, column: String, data: T)
我的 class 以下列方式调用:
updateItemInDb(it, DB_POS, i)
,其中 it
是 Long
,DB_POS
是 String
,i
是 Int
。
我希望函数只 运行 不做任何事情。我在单元测试中尝试了以下内容:
1) every { adapter["updateItemInDb"](any<Long>(), any<String>(), any<Int>()) } just Runs
这给了我一个类型不匹配错误:required MockKStubScope<Unit>, found MockKStubScope<Any?>
2) every { adapter["updateItemInDb"](any<Long>(), any<String>(), any<Int>()) } answers { }
这在 运行 时间失败 io.mockk.MockKException: can't find function updateItemInDb(-1078155520644112829, -d008fa83c4f49c0, 843241211) for dynamic call
现在是了。通用私有函数自 1.7.16
以来已修复
我想模拟以下功能:
private fun <T> updateItemInDb(id: Long, column: String, data: T)
我的 class 以下列方式调用:
updateItemInDb(it, DB_POS, i)
,其中 it
是 Long
,DB_POS
是 String
,i
是 Int
。
我希望函数只 运行 不做任何事情。我在单元测试中尝试了以下内容:
1) every { adapter["updateItemInDb"](any<Long>(), any<String>(), any<Int>()) } just Runs
这给了我一个类型不匹配错误:required MockKStubScope<Unit>, found MockKStubScope<Any?>
2) every { adapter["updateItemInDb"](any<Long>(), any<String>(), any<Int>()) } answers { }
这在 运行 时间失败 io.mockk.MockKException: can't find function updateItemInDb(-1078155520644112829, -d008fa83c4f49c0, 843241211) for dynamic call
现在是了。通用私有函数自 1.7.16
以来已修复