Christoph Flick
10/06/2020, 10:07 PMfun Application.main() {
di {
bind<SomeService>() with singleton { SomeService(environment.config) }
}
...
I use the service somewhere in the app, in the routes, etc.
My tests (kotest) look like that:
"A Request should do something" {
withServer {
val req = handleRequest {
uri = "/someroute"
}
req.requestHandled shouldBe true
req.response shouldHaveStatus HttpStatusCode.OK
}
}
withServer
is a wrapper for withTestApplication({ main() }, test)withTestApplication({ main() }, block)
My problem is that I currently need to test against a real database as I don't get the DI mock to work.
Any hints for me here?
Thanks!romainbsl
10/08/2020, 1:07 PMval appDI = DI {
bind<SomeService>() with singleton { SomeService(environment.config) }
}
fun Application.run(di: DI) {
di {
extend(appDI)
}
}
fun Application.main() {
run(appDI)
}
and in your tests something like
val mockDI = DI {
bind<SomeService>() with singleton { SomeMockService() }
}
withTestApplication({ run(mockDI) }, test)
Christoph Flick
10/09/2020, 11:43 AM