Hello team, I'm writing a custom ktor client plugi...
# ktor
x
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
You should always also test with a real setup. You can do this by running an embeddedServer in your tests.
x
Oh there's no way to test a plugin against a mock client engine then ? Thanks
h
Nope, the mock engine is very low level and returns the response directly without the pipeline.
a
Can you describe what your plugin does?
x
A couple of things like monitoring the requests but also updating some headers in outgoing requests
a
You can try using the testApplication function to test your plugin.