Leonardo Borges
12/02/2021, 3:04 PMmockK
.
class MyUseCase {
operator suspend fun invoke(val someId: UUID) = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
val response = someAPI.requestDataById(someId)
// process the response...
}
}
Using JUnit5, there are a few exceptions I want to test, such as below:
@Test
fun testCustomExceptionIsThrown() {
coEvery { someAPI.requestDataById(someId) returns someData }
val thrown = assertThrows<CustomException> {
runBlocking { myUseCase(someId) }
}
assertEquals("customExceptionMessage", thrown.message)
}
This is always returning an JobCancellationException: Parent job is Completed;
and I actually can't figure out why.
Also, is this the right way to use those libraries?xiaobailong24
12/03/2021, 5:03 AM