Ktor 3.4.1 Help

Testing with dependency injection

The dependency injection (DI) plugin provides tooling to simplify testing.

You can override dependencies before loading your application modules:

fun test() = testApplication { application { dependencies.provide<MyService> { MockService() } loadServices() } }

In the above example loadServices() is the function that bootstraps your application's modules — for example, the function that registers your routes and services, equivalent to what is listed under modules in your application.yaml.

Loading configuration in tests

Use configure() to load configuration files easily in your tests:

fun test() = testApplication { // Load properties from the default config file path configure() // Load multiple files with overrides configure("root-config.yaml", "test-overrides.yaml") }

Conflicting declarations are ignored by the test engine to let you override freely.

27 February 2026