Richard Schielek
11/27/2022, 5:29 PMfun Application.configureRouting() {
routing {
get("/") {
error("Something went wrong")
}
}
}
But when using this in a test, the test application will not return a 500 but throw the exception instead
class ApplicationTest {
@Test
fun testRoot() = testApplication {
application {
configureRouting()
}
val response = client.get("/") // java.lang.IllegalStateException: Something went wrong
assertEquals(HttpStatusCode.InternalServerError, response.status)
}
}
How do I test this behavior when I rely on the default implementation of ktor?Rustam Siniukov
11/28/2022, 11:11 AMktor.test.throwOnException=false
to your config. For example like this in
testApplication {
environment {
config = MapApplicationConfig("ktor.test.throwOnException" to "false")
}
....
}
Richard Schielek
11/28/2022, 11:12 AMRichard Schielek
11/28/2022, 11:13 AMRustam Siniukov
11/28/2022, 11:30 AM