doSuspendableAnswer

infix fun <T> OngoingStubbing<T>.doSuspendableAnswer(answer: suspend (KInvocationOnMock) -> T?): OngoingStubbing<T>

Sets an answer to be applied when the stubbed suspendable function is being called, specified by a suspendable lambda. E.g:

    whenever { mock.someFunction() } doSuspendableAnswer { "result" }

This function is an alias for Mockito's OngoingStubbing.thenAnswer, but also taking extra steps to wire the suspendable lambda answer properly into the Kotlin's coroutine context of the stubbed suspendable function call.

Return

OngoingStubbing object used to stub fluently. Do not create a reference to this returned object.

Parameters

answer

to be applied on the suspendable function invocation.


fun <T> doSuspendableAnswer(answer: suspend (KInvocationOnMock) -> T): Stubber

Sets a generic answer, specified with a suspendable lambda, to be applied in reverse stubbing.

Example:

    doSuspendableAnswer { "result" }.whenever(mock).someMethod()

This function is an alias for Mockito's Mockito.doAnswer, but also taking extra steps to wire the suspendable lambda answer properly into the Kotlin's coroutine context of the stubbed suspendable function call.

See examples in javadoc for Mockito class

Return

Stubber object used to stub fluently.

Parameters

answer

to answer to apply when the stubbed method/function is being called.