lundi 14 octobre 2019

How to wait until io.mockk captured slots will be filled while calling a method that contains asynchronous operations? (Unit Test)

PS: Codes in Kotlin

In my unit test,

I have mutable list of string called slot

val slot = mutableListOf<String>()

I captured this slot list

every { someService.whateverMethod(capture(slot)) } just Runs

In the end of certain test I check size of slot.

slot.size shouldBe 2

A method that I test contains asynchronous operations. Accordingly, I should write Thread.sleep(1000) before checking slot size (slot.size shouldBe 2)

How to refuse Thread.sleep(1000) operation, and make something that will wait for 1 second. Something like verify(timeout = 10000).

Aucun commentaire:

Enregistrer un commentaire