https://kotlinlang.org logo
Title
p

Pablo

11/06/2020, 11:16 AM
Is there any way to check that a couroutineScope is cancelled? on my Unit test I want to check that my coroutineScope is cancelled at some point. The thing is my CoroutineScope is not a mock so I can not use verify.
e

ephemient

11/06/2020, 11:27 AM
there's
val CoroutineScope.isActive: Boolean
, is that enough for you?
otherwise you can chain together
suspend val coroutineContext: CoroutineContext /* OR */ suspend fun currentCoroutineContext(): CoroutineContext
val CoroutineContext.job: Job
val Job.isCancelled: Boolean
p

Pablo

11/06/2020, 11:43 AM
I've thought about that
isActive
, but didn't know if it would do the job, I'm going to try it. But I want to check if it's called the
cancel()
at some point... So that's why I'd need the verify there
g

gildor

11/06/2020, 2:21 PM
isActive is way to go, but it also will be false if Job is finished