Hi I want to mock my method ```fun wait(){ val...
# mockk
h
Hi I want to mock my method
Copy code
fun wait(){
    val timeout= TimeHelper.getNow() + timeoutInterval // <- part of class constructor
    if(processor.getLag() > 0){
        val currentTIme = TimeHelper.getNow() 

        if(currentTime >= timeout){ System.exit(42) }
        Thread.sleep(someTime)
    }
}
Is there a way for me to use mockk to either that
wait()
has executed for x amount of time with
verify(exactly = x) { someProcessor.wait() }
, or
Thread.sleep()
has been sleeping for x number of time? I have something like this in my test class
Copy code
every { processor.getLag() } returns 1
every { TimeHelper.getNow() } returns 100
So after some number of executions
ever{ processor.getLag() } returns 0
to validate that it finishes
m
short answer: no longer answer: I think you’d be better using coroutines,
runBlocking
and
delay
rather than
Thread.sleep()
that way, by using
runBlockingTest
in your test you can test the rest of your code without the delays
130 Views