https://kotlinlang.org logo
#coroutines
Title
# coroutines
l

Lukasz Kalnik

01/25/2023, 3:52 PM
In a unit test, using
runTest
, can I somehow test that coroutine suspended and not continued?
The use case is related to my thread above - I want to test
suspendCancellableCoroutine
getting a callback, which then doesn't trigger a continuation to resume
s

Sam

01/25/2023, 3:56 PM
Something like this?
Copy code
runTest {
    val job = async { doSomething() }
    runCurrent()
    assertFalse(job.isCompleted)
    job.cancel()
}
l

Lukasz Kalnik

01/25/2023, 4:02 PM
That seems to work well. Thank you for your help! 🙏
3 Views