Is there any way to still obtain the `TestApplicat...
# ktor
p
Is there any way to still obtain the
TestApplicationEngine
when using the new
testApplication
API (and is there any link to the 2.0 docs anywhere? I can’t seem to find anything to help navigating the new APIs)
d
I think you can get the engine from the client.
r
Can you explain why do you need it?
p
Previously we were using the
handleRequest
method within our test cases and asserting over the
TestApplicationCall
(using a number of custom assertion helpers) - I’m currently updating this to use the new
testApplication
API due to the deprecation warning.
r
btw, while doc is in progress, you can see design ticket https://youtrack.jetbrains.com/issue/KTOR-971
p
Thank you 🙂 I’ll give it a read as it might shed some light on how to approach the new API 🙏
r
Please note that implementation differs a bit from what is in the design. Check this comment https://youtrack.jetbrains.com/issue/KTOR-3236#focus=Comments-27-5474765.0-0
👍 1
eap docs are available here https://ktor.io/docs/eap/testing.html
🙏 1
p
Quick follow-on - I have a use-case where a route needs to call an external service. Currently under test we inject a
MockEngine
when setting up the route however the external-services hook stuff looks interesting for this use-case, however I would guess the
client
isn’t available to inject into the routes until after the TestApplication has been built?
r
can you provide code snippet for this, please?
p
Seems like it is possible (as the
application {}
block isn’t actually invoked until it’s all configured) - I was worried that the call for
client
would create the engine and cause further config to fail (or not be picked up) however due to the use of
DelegatingTestClientEngine
it seems to work fine :)
👍 1