KamilH
05/04/2022, 10:09 AMwithTestApplication
where I call Application.module
function with some arguments like that:
withTestApplication({
module(appModule = appModule)
}) { ... }
now we are suppose to use testApplication
function that seemingly calls Application.module
function automatically, so passing custom arguments seems not possible anymore and it makes testing much more difficult. Is there any way to call Application.module
manually? Is there any workaround?phldavies
05/04/2022, 10:12 AMtestApplication {
application {
module(appModule = appModule)
}
// ... test using `client` or `createClient { ... }`
}
hruan
05/04/2022, 10:15 AMtestApplication
picks up application.conf
and will automatically load modules there (e.g. Application.module
. If you want a different set of modules all together, you can modify `environment`: https://ktor.io/docs/testing.html#add-modulesKamilH
05/04/2022, 10:15 AMApplication.module
gets called twice, so my plugins gets installed twice and it results in exceptionKamilH
05/04/2022, 10:17 AMphldavies
05/04/2022, 10:17 AMtestApplication {
environment {
modules.clear()
modules.add(appModule)
}
}
ribesg
05/04/2022, 10:24 AMtestApplication
should have a useApplicationConf: Boolean = true
parameter or something like that to let you disable this behavior. Maybe I want an application.conf
file in my main source set and maybe I don’t want to use it in my testsphldavies
05/04/2022, 10:24 AMenvironment
block: https://ktor.io/docs/testing.html#environmentribesg
05/04/2022, 10:26 AMphldavies
05/04/2022, 10:28 AMribesg
05/04/2022, 10:29 AMtestApplication
block happened after the config had been read but maybe it’s not the casephldavies
05/04/2022, 10:30 AMtestApplication
block doesn’t action the configuration until the first client request is made (and the test engine is started)KamilH
05/04/2022, 10:32 AM.conf
file in test/resource
folder, mentioned here worked well. I’ve left modules
empty and no modules are loaded:
// test/resource/application-test.conf
ktor {
application {
modules = [ ]
}
}
@Test
fun test() = testApplication {
environment {
config = ApplicationConfig("application-test.conf")
}
}