https://kotlinlang.org logo
#koin
Title
t

Tucker Barbour

11/20/2019, 1:11 PM
I’m also interested in this (or something similar). I’d like to be able inject mock dependencies into a ktor application in the test and then verify the mocks. This seems to work but I’m curious if this is the recommended approach.
Copy code
@Test
fun test() = withTestApplication(Application::main) {
  val service = mockk<Service>()
  declare {
    single<Service> { service }
  }

  with(handleRequest(HttpMethod.Get, "/")) {
    assertThat(response.status()).isEqualTo(HttpStatusCode.OK)

    verify(exactly = 1) { service.call(any()) }
  }
}