https://kotlinlang.org logo
#ktor
Title
# ktor
s

S.

04/04/2022, 6:19 PM
how do you test endpoints that return status codes like
NotFound
or
BadRequest
since they throw
io.ktor.client.plugins.ClientRequestException
? so this below doesn't work, only way is to do the checks on the exception's message it seems
Copy code
val response = client.get("api/v1/words/x")
response shouldHaveStatus HttpStatusCode.BadRequest
response.bodyAsText() shouldBe INVALID_ID
replace e.g. `NotFound`with
NoContent
?
a

Aleksei Tirman [JB]

04/04/2022, 6:24 PM
You can disable default response validation by assigning the value
false
to the
expectSuccess
property in the client’s configuration to test them without an exception.
s

S.

04/04/2022, 6:26 PM
oh great, ty
3 Views