I have a simple hello world Ktor app:
fun Application.testMe() {
intercept(ApplicationCallPipeline.Call) {
if (call.request.uri == "/")
call.respondText("Hello")
}
}
With JUnit test class I can write the test for it, as given in its documentation; as following:
class ApplicationTest {
@Test fun testRequest() = withTestApplication(Application::testMe) {
with(handleRequest(HttpMethod.Get, "/")) {
assertEquals(HttpStatusCode.OK, response.status())
assertEquals("Hello", response.content)
}
with(handleRequest(HttpMethod.Get, "/index.html")) {
assertFalse(requestHandled)
}
}
}
However, I want to do a unit test in Spek or KotlinTest, without the help of JUnit, similar to the way I do it in ScalaTest/Play; in a more declarative way:
- Send a FakeRequest to the route (i.e.,
/
) during a test. - Get the content of the page, and check for the string "hello".
The question is can I write the above test in a more declarative way in KotlinTest or Spek?