HTTP tests
HttpTestClient resolves HttpKernel from a booted app and runs requests in-process (no listen socket).
Create a client
Section titled “Create a client”val http = HttpTestClient(app)http.get("/ping").assertOk().assertJsonContains("ok")HttpTestClient http = new HttpTestClient(app);http.get("/ping").assertOk().assertJsonContains("ok");Register routes before calling the client (provider boot, or after TestApplication.create).
| Method | Notes |
|---|---|
get(uri) / get(uri, headers) |
Empty body |
postJson(uri, body) / postJson(uri, body, headers) |
Serializes body with Jackson; sets Content-Type: application/json |
put(uri) / put(uri, body) / put(uri, body, headers) |
Raw string body |
putJson(uri, body) / putJson(…, headers) |
JSON encode |
patch(uri) / patch(uri, body) / patch(…, headers) |
Raw string body |
patchJson(uri, body) / patchJson(…, headers) |
JSON encode |
delete(uri) / delete(uri, headers) |
Empty body |
Headers maps are plain Map<String, String>. Query strings belong in the uri.
http.postJson("/users", mapOf("name" to "Ada")) .assertStatus(201) .assertJsonPath("user.name", "Ada")
http.putJson("/users/1", mapOf("name" to "Ada Lovelace"), mapOf("X-Request-Id" to "r-1")) .assertOk()
http.delete("/users/1").assertStatus(204)http.postJson("/users", Map.of("name", "Ada")) .assertStatus(201) .assertJsonPath("user.name", "Ada");
http.putJson("/users/1", Map.of("name", "Ada Lovelace"), Map.of("X-Request-Id", "r-1")) .assertOk();
http.delete("/users/1").assertStatus(204);Response assertions
Section titled “Response assertions”Every verb returns a TestResponse (fluent — assertions return this).
| Method | Behavior |
|---|---|
status() / body() |
Raw values for custom asserts |
assertStatus(code) |
Exact status; throws if mismatched |
assertOk() |
Status 200 |
assertJsonContains(fragment) |
Body string contains substring |
assertJsonPath(path, expected) |
Dotted JSON path (user.name) equals expected |
assertJson(path, expected) |
Alias for assertJsonPath |
Path segments are split on .. Missing segments fail the assertion. Numbers compare by double equality (so 1 and 1.0 match). null JSON nodes compare to Kotlin/Java null.
Edge cases
Section titled “Edge cases”- The client does not follow redirects; assert the first response.
- Middleware on the kernel runs normally — CSRF, session, and auth behave as in production when those providers are registered.
- Bodies for non-JSON
put/patchare raw strings; encode your own payload when needed.