I'm relative new to Kotlin and I'm trying to test ...
# coroutines
l
I'm relative new to Kotlin and I'm trying to test a use case which has a suspend function. The function calls an API, which I'm mocking using
mockK
.
Copy code
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:
Copy code
@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?