Predict the output
How long does this test take in real time?
@Test
fun retriesAfterDelay() = runTest {
var attempts = 0
repeat(3) {
attempts++
delay(10_000)
}
assertEquals(3, attempts)
}Hint 1 of 1
What kind of clock does runTest use?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A A few milliseconds
Correct. runTest uses virtual time, so delays are skipped.
Why not the others?
- B 30 seconds. That's runBlocking behaviour.
- C 10 seconds. runTest doesn't wait for any of the delays.
- D It times out after 10 seconds. Virtual delays don't count towards the real timeout.