I'm trying to test a suspend method which first tr...
# coroutines
s
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
Copy code
override suspend fun validate(thingy: String): Result {
  return try {
    webClient.validate(thingy)
  } catch(e: Exception) {
    offlineValidator.validate(thingy)
  }
}
here's the test method:
Copy code
@Test
fun testOfflineValidation() = mainCoroutineRule.runBlockingTest {
    val result = sut.validate("stuff")
}
s
Is the exception an
Exception
or a
Throwable
.?
s
in my fake, I do
throw Exception()
. The real one is going to use Retrofit, so I'm not sure what it does
s
Hmmm…. then your code catches the right type of exception… not sure what is going on. Try to debug it, step by step….
s
I have, but it doesn't go into the catch block
nevermind, I wasn't setting up my fake properly
👍 1