Skip to main content
Version: 6.0 🚧

Ktor

The kotest-assertions-ktor module provides response matchers for a Ktor application. There are matchers for both TestApplicationResponse if you are using the server side test support, and for HttpResponse if you are using the ktor HTTP client.

To add Ktor matchers, add the following dependency to your project

io.kotest:kotest-assertions-ktor:${version}
note

Since Kotest 6.0, all extensions are published under the io.kotest group once again, with version cadence tied to main Kotest releases.

An example of using the matchers with the server side test support:

withTestApplication({ module(testing = true) }) {
handleRequest(HttpMethod.Get, "/").apply {
response shouldHaveStatus HttpStatusCode.OK
response shouldNotHaveContent "failure"
response.shouldHaveHeader(name = "Authorization", value = "Bearer")
response.shouldNotHaveCookie(name = "Set-Cookie", cookieValue = "id=1234")
}
}

And an example of using the client support:

val client = HttpClient(CIO)
val response = client.post("http://mydomain.com/foo")
response.shouldHaveStatus(HttpStatusCode.OK)
response.shouldHaveHeader(name = "Authorization", value = "Bearer")