https://kotlinlang.org logo
#mockk
Title
# mockk
h

Helio

06/16/2022, 4:42 AM
Hello guys 👋🏽 I was wondering if anyone who migrated from Ktor V1 to V2 had any issues with
mockk
? During the migration our team noticed that some of our Integration tests were breaking because
mockk
is no longer able to mock Ktor HttpClients. Does anyone knows anything about that? I read through the Ktor migration guided but I could not find any behaviour change. For example: The snippet below used to work with Ktor v1, but it is no longer working with Ktor v2.
Copy code
myHttpClient = mockk<MyHttpClient>()
mockkObject(MyHttpClient)
coEvery { MyHttpClient.getClient() } returns myHttpClient
Any tip would be greatly appreciated.
s

Sam

06/16/2022, 9:38 AM
Normally I use ktor-client-mock when testing with Ktor clients, instead of using
mockk
HttpClient
is one of those APIs where
mockk
doesn't work well because there are just too many extension functions and plugin behaviours to worry about
When you say "it is no longer working", what error or problem are you seeing?
h

Helio

06/16/2022, 9:43 PM
The problem was that instead of
MyHttpClient.getClient()
get mocked, the tests were trying to accessing
getClient()
.
This is a reference of my conversation with Ktor in case anyone faces a similar problem.
2 Views