It is designed to bridge regular blocking code to libraries that are written in suspending style, to be used in main functions and in tests.
And I think this is probably a valid case, where you need to bridge regular blocking code. JUnit doesn't support suspending.
Alternatively, you could probably also make a helper function, that does cleanup.
Copy code
@Test
fun someTest() {
runTestAndCleanup {
// test code
}
}
private fun runTestAndCleanup(block: suspend () -> Unit) = runTest {
try {
block()
} catch(e) {
TODO("cleanup")
throw e
}
}
a
Abhimanyu
09/01/2023, 7:52 PM
Thanks, the helper function seems like a better idea.
Currently I had the cleanup code in a separate method and I was calling it in all tests. (it can be missed easily in new tests.)