我注意到有时会verify
因“......调用......发生,但参数不匹配”而失败
这是一个显示验证失败的示例测试:
class TestStuff {
val stuff = "1"
@RelaxedMockK
lateinit var testService: TestService
@RelaxedMockK
lateinit var testInterface: TestInterface
@Before
fun setup() {
MockKAnnotations.init(this)
every { testInterface.testStuff } returns stuff
}
@Test
fun testStuffCalled() {
testService.testStuff(testInterface.testStuff)
verify { testService.testStuff(testInterface.testStuff) }
}
}
interface TestInterface {
val testStuff: String
}
class TestService {
fun testStuff(stuff: String) {
}
}
如果我将带有验证调用的行更改为以下 2 行,那么它可以工作:
let testStuffCopy = testInterface.testStuff
verify { testService.testStuff(testStuffCopy) }