https://kotlinlang.org logo
#ktor
Title
# ktor
p

phldavies

01/04/2022, 11:12 AM
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

Dominaezzz

01/04/2022, 2:02 PM
I think you can get the engine from the client.
r

Rustam Siniukov

01/04/2022, 2:38 PM
Can you explain why do you need it?
p

phldavies

01/04/2022, 4:46 PM
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

Rustam Siniukov

01/04/2022, 5:04 PM
btw, while doc is in progress, you can see design ticket https://youtrack.jetbrains.com/issue/KTOR-971
p

phldavies

01/04/2022, 5:10 PM
Thank you 🙂 I’ll give it a read as it might shed some light on how to approach the new API 🙏
r

Rustam Siniukov

01/04/2022, 6:08 PM
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

phldavies

01/06/2022, 12:54 PM
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

Rustam Siniukov

01/06/2022, 2:50 PM
can you provide code snippet for this, please?
p

phldavies

01/06/2022, 5:13 PM
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
35 Views