Testing
Test your Funktor app with fixtures, service injection, and route testing utilities.
AppSpec
Extend AppSpec to get a running test server with full Kontainer support.
Uses Kotest FreeSpec style.
class UserApiSpec : AppSpec<MyConfig>(testBed) {
init {
installAllFixturesBeforeSpec()
"GET /api/users" - {
"returns user list" {
val response = engine.handleRequest(HttpMethod.Get, "/api/users")
response.status() shouldBe HttpStatusCode.OK
}
}
}
} Service injection in tests
Access any service from the test Kontainer using delegated properties.
class UserServiceSpec : AppSpec<MyConfig>(testBed) {
val userService: UserService by service()
val userRepo: UserRepo by service()
init {
"UserService" - {
"creates user" {
val user = userService.create("test@example.com")
user.email shouldBe "test@example.com"
}
}
}
} Fixtures in tests
Install fixtures before each spec or before individual tests. Fixtures are cleared and re-installed to ensure a clean state.
class OrderSpec : AppSpec<MyConfig>(testBed) {
init {
installFixturesBeforeSpec(UserFixtures::class, OrderFixtures::class)
"order processing" - {
"calculates total" {
val fixtures = kontainer().get(OrderFixtures::class)
val order = fixtures.sampleOrder.get()
order.total shouldBe 42.0
}
}
}
} The test harness starts a real Ktor engine and connects to a real database.
No mocking, no in-memory fakes. If it passes in tests, it works in production.