Hello team, I'm writing a custom ktor client plugin, and I'd like to write unit tests. I tried applying the plugin to a client with the official MockEngine, but it seems my plugin's callback (
onRequest
and
onResponse
) are never called with the MockEngine, but they are with the real one. Is there a best practice to test a client plugin ?
h
hfhbd
07/12/2024, 7:24 AM
You should always also test with a real setup. You can do this by running an embeddedServer in your tests.
x
Xavier F. Gouchet
07/12/2024, 8:29 AM
Oh there's no way to test a plugin against a mock client engine then ? Thanks
h
hfhbd
07/12/2024, 8:30 AM
Nope, the mock engine is very low level and returns the response directly without the pipeline.
a
Aleksei Tirman [JB]
07/12/2024, 9:30 AM
Can you describe what your plugin does?
x
Xavier F. Gouchet
07/12/2024, 11:22 AM
A couple of things like monitoring the requests but also updating some headers in outgoing requests
a
Aleksei Tirman [JB]
07/15/2024, 7:14 AM
You can try using the testApplication function to test your plugin.