library. And we are facing some problems with mocking objects. What is the best way to test
ktor
application? Assuming we need to mock some stuff that goes to third-party services? Any tough samples? Thanks.
c
CLOVIS
12/30/2022, 3:23 PM
You can use https://ktor.io/docs/testing.html to generate a temporary server that fakes HTTP actions, and a Client instance that calls it
CLOVIS
12/30/2022, 3:23 PM
If you want to fake a third-party service, you can just declare it as a route in that fake service, and the client will call it
r
rcd27
12/30/2022, 3:28 PM
We need to mock the exact object inside our app.
rcd27
12/30/2022, 3:28 PM
We already use
testApplication
with
createClient
DSLs.
r
Roman Pavlyuk
12/31/2022, 5:36 PM
Copy code
testApplication {
//mock top level getStuff() func
mockkStatic("my.package.name.ClassKt")
every { getStuff() } returns listOf(Stuff(), Stuff())
// mock class
val repository = mockk<MyRepository>()
val target = MyService(repository)
every { repository.save(any()) } just Runs
}