ktorio / ktor

Framework for quickly creating connected applications in Kotlin with minimal effort
https://ktor.io
Apache License 2.0
12.86k stars 1.04k forks source link

KTOR-7043 Explicit testApplication configuration from file #4065

Closed bjhham closed 3 months ago

bjhham commented 4 months ago

Subsystem Testing

Motivation KTOR-7043 Test Application explicit loading of modules

I noticed this when generating projects with the file configuration options (hocon or yaml), the tests would break due to duplicate modules being loaded. This seems like a pretty significant design problem with the testApplication API, because it makes it so you cannot change your configuration without breaking all of your tests, and it hinders test isolation for checking particular modules.

Solution Removed implicit DefaultTestConfig function call for JVM tests, and instead use an empty MapConfiguration for all platforms.

The current solution could perhaps be improved with some additional DSL. If you want to load the file confuration now, you need something like this:

environment {
    config = ConfigLoader.load()
}

Note, this should only go into 3.0.0.