I have a class like this
class SomeClass {
fun someFun() {
// ... Some synchronous code
async {
suspendfun()
}
}
private suspend fun suspendFun() {
dependency.otherFun().await()
// ... other code
}
}
I want to unit test someFun()
so I wrote a unit test that looks like this:
@Test
fun testSomeFun() {
runBlocking {
someClass.someFun()
}
// ... verifies & asserts
}
But this doesn't seem to work because runBlocking doesn't actually block execution until everything inside runBlocking is done. If I test suspendFun()
directly inside runBlocking
it works as expected but I want to be able to test someFun()
all together.
Any clue how to test a function with both sync and async code?