mockk 异常 - 没有找到答案

mockk exception - no answer found for

使用 mockk 测试 kotlin 功能。

private val serviceObject = mockk<Service>()
private val serviceToBeTested = ServiceToBeTestd(Service)
        
fun test(){
    when(serviceObject.function1(argument1,argument1))
        .thenReturn(<something>)
}

当我尝试 运行 它时,我得到这个错误:

io.mockk.MockKException: no answer found for: Service(#1).function1(argument1, argument2)

知道为什么吗?

ServiceToBeTestd为待测服务,Service连线在其中:

open class ServiceToBeTestd
    constructor(private val service: Service)

您正在使用 mockito 语法。

以下是 mockk 的正确语法。

val car = mockk<Car>()

every { car.drive(Direction.NORTH) } returns Outcome.OK

请更新您的语法。