我目前正在使用Kotest和MockK在Kotlin编写测试. 在使用kotest和MockK用Kotlin编写测试时,我在模拟过程中遇到了一个错误.
every { accountService.findAccount(nonExistAccountId.toString()) } just Runs
//Kotlin: Type mismatch: inferred type is Runs but Awaits was expected
但之前,我在同样的过程中没有遇到任何问题.
every { noticeRepository.delete(any()) } just Runs
//no error
所以,我判断了"公正"的声明.
/**
* Part of DSL. Answer placeholder for Unit returning functions.
*/
@Suppress("UNUSED_PARAMETER")
infix fun MockKStubScope<Unit, Unit>.just(runs: Runs) = answers(ConstantAnswer(Unit))
/**
* Part of DSL. Answer placeholder for never returning suspend functions.
*/
@Suppress("UNUSED_PARAMETER")
infix fun <T, B> MockKStubScope<T, B>.just(awaits: Awaits) = coAnswers { awaitCancellation() }
为什么上面的函数没有被调用?