-
Notifications
You must be signed in to change notification settings - Fork 207
Coroutines
Joshua Selbo edited this page Apr 22, 2026
·
3 revisions
Mockito-Kotlin supports stubbing and verifying with suspendable functions (those marked with suspend). This is possible without the need to create a coroutine context, e.g. using runTest {} from kotlinx.coroutines.test.
As of Mockito-Kotlin 6.2.0, the core whenever and KStubbing APIs support calling suspend functions directly:
whenever { myMock.suspendFoo() } doReturn value
mock<MyClass> {
on { suspendFoo() } doReturn value
}Use verifyBlocking to verify suspendable functions:
verifyBlocking(myMock) { suspendFoo() }