Hi,
I haven't found a way until now to unit test a suspend function using spock.
If anyone can shed some light on this please do so.
Thanks
You can try calling your suspending function from runBlocking { ... } and then testing the result of that.
I cannot use runBlocking from spock, however this is a good idea. I could create a wrapper kotlin function with runBlocking{}. Thanks, I'll try.
You could also mock that Continuation object, which kotlin is compiling into the method call. This code worked for me:
// mocked continuation
def continuation = Mock(Continuation) {
getContext() >> Mock(CoroutineContext)
}
// method call which should be tested
subjectUnderTest.suspendableMethod(someParameter, continuation)
Most helpful comment
You could also mock that Continuation object, which kotlin is compiling into the method call. This code worked for me: