Anthony Legay
04/02/2024, 9:29 AMexternalServices dsl in the testApplication (https://ktor.io/docs/testing.html#external-services)
• using HttpClient MockEngine (https://ktor.io/docs/http-client-testing.html)
the first comes from ktor server, and the second method comes from ktor client but the two seems to address the same goal.
So my question is, what would be the main difference between the two ? Are there features one can do and the other can’t ?
The objective is to intercept calls and just mock responses by returning fake JSON files stored locally.
Thanks in advance!Aleksei Tirman [JB]
04/02/2024, 9:33 AMtestApplication is to write server tests without making network calls. The purpose of the MockEngine is to avoid making network requests within the tests which require the HTTP client usage.Aleksei Tirman [JB]
04/02/2024, 9:34 AMMockEngine if you need to stub HTTP client requests.Anthony Legay
04/02/2024, 9:41 AMexternalServices block, in the example from the website, avoid making calls to the Google APIs by mocking them, isn’t it the same than using a MockEngine and mocking the calls too ? (Because we need to pass a HttpClient instance to the oauth("auth-oauth-google") { block, we could also pass a mocked HttpClient).
I’m sorry I’m just confused if there is really a difference or if it’s just a matter of taste.Aleksei Tirman [JB]
04/02/2024, 9:43 AMtestApplication . If you only use the client then MockEngine is preferred way.Anthony Legay
04/02/2024, 9:44 AM