ddimitrov
08/18/2022, 3:20 PMfun testPostCustomer() = testApplication {
val client = createClient {
install(ContentNegotiation) {
json()
}
}
val response = <http://client.post|client.post>("/customer") {
contentType(ContentType.Application.Json)
setBody(Customer(3, "Jet", "Brains"))
}
assertEquals("Customer stored correctly", response.bodyAsText())
assertEquals(HttpStatusCode.Created, response.status)
}
I find that to be broken, as the closure argument of the test application configures the application builder, and executing the stimuli and the assertions mean that you are running these from your app config code before the app is started. I am not even sure how it ever works, even if sometimes it does.
In my case, my app is starting an event pump for external Java API (think TIBCO RV) from the ApplicationStarted event, and this callback is invoked at the end of the test, after all assertions have failed (I found that only after commenting out a lot of code).
Raised: https://youtrack.jetbrains.com/issue/KTOR-4773