Skip to main content
Version: 5.5

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.extensions:kotest-assertions-ktor:${version}

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")