简体   繁体   English

Mockk in Kotlin:传递来验证的参数不是模拟

[英]Mockk in Kotlin: Argument passed to verify is not a mock

I have defined my mock as follows: 我将模拟定义如下:

private val dal = mockk<UserDal> {
    every { insert(any()) } returnsArgument 0
}

Then, I'm trying to test it like this: 然后,我试图像这样测试它:

@Test
fun test() {
    userService.registerUser(userJohn)

    verify(dal).insert(check {
        assertEquals(it.firstName, "John")
    })
}

This throws an exception: 这将引发异常:

org.mockito.exceptions.misusing.NotAMockException: 
Argument passed to verify() is of type UserDal and is not a mock!
Make sure you place the parenthesis correctly!

I don't understand how it's saying that the UserDal is not a mock, when it clearly is! 我不明白这是怎么说的, UserDal并不是模拟的,而是明显的! What is wrong with this code? 此代码有什么问题? How can I verify the argument fields? 如何验证参数字段?

Mockito and MockK are two different, incompatible mocking frameworks. Mockito和MockK是两个不同的,不兼容的模拟框架。 You cannot use the Mockito API to stub or verify mocks created by MockK. 您不能使用Mockito API存根或验证MockK创建的模拟。 The reverse is true, too. 反之亦然。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM