zak.taccardi
07/18/2024, 2:20 AMbackgroundScope
before runTest { }
completes, and prevent it from throwing that exception at the end of the runTest { }
function?zak.taccardi
07/18/2024, 2:22 AMbackgroundScope
provides, but with the the inline exception throwing of TestScope
and UnconfinedTestDispatcher
My use case is that I want to leverage some type of assertFailsWith(..)
logic on the exceptions that occurred before runTest completeszak.taccardi
07/18/2024, 3:51 AMrunTest { }
in an assertFailsWith<Exception>{ }
.
// this works
@Test
fun currentSolution() {
assertFailsWith<IllegalStateException> {
executeTest {
// executed on a background scope
whenExceptionIsIntentionallyThrown()
}
}
}
I would prefer to be able to do something like this:
// does not work
@Test
fun doesNotCatchException() = executeTest {
// executed on a background scope
whenExceptionIsIntentionallyThrown()
assertFailsWith<IllegalStateException> {
thenIllegalStateExceptionWasThrown()
}
}
I need to access the exceptions thrown under the backgroundScope
before runTest { }
completes. Is it possible?CLOVIS
07/19/2024, 8:21 AMzak.taccardi
07/19/2024, 8:51 PMThe background scope is meant to model tasks that are independent of the system-under-testwhat do you mean by this? we have a lot of ongoing actor coroutines in our codebase that build ongoing state. we don’t care about manually closing these. In production,
scope.cancel()
is meant to gracefully shut down these actor coroutines. My understanding is that this is what backgroundScope
is for. Am I wrong here?CLOVIS
07/21/2024, 12:23 PM