I'm trying to test a suspend method which first tries to reach an API, but if that throws an exception, would fall back to a local method. However, it doesn't appear the catch in the suspend method is being executed
Steve
03/16/2020, 6:20 PM
Copy code
override suspend fun validate(thingy: String): Result {
return try {
webClient.validate(thingy)
} catch(e: Exception) {
offlineValidator.validate(thingy)
}
}
Steve
03/16/2020, 6:24 PM
here's the test method:
Copy code
@Test
fun testOfflineValidation() = mainCoroutineRule.runBlockingTest {
val result = sut.validate("stuff")
}
s
streetsofboston
03/16/2020, 6:29 PM
Is the exception an
Exception
or a
Throwable
.?
s
Steve
03/16/2020, 6:33 PM
in my fake, I do
throw Exception()
. The real one is going to use Retrofit, so I'm not sure what it does
s
streetsofboston
03/16/2020, 6:35 PM
Hmmm…. then your code catches the right type of exception… not sure what is going on.
Try to debug it, step by step….