https://kotlinlang.org logo
Title
e

eirikb

08/29/2019, 9:59 AM
How do I use MockEngine (https://ktor.io/clients/http-client/testing.html)? I can see how I can set it up, but I have a class with a private
HttpClient
d

Dominaezzz

08/29/2019, 10:05 AM
Your class has to accept an engine via it's ctor or something.
e

eirikb

08/29/2019, 10:07 AM
I started doing something like that, but with whole config, problem was that I must remember to make my tests have same install as my service, and
client.config { install  { ... }}
didn't seem to work. But passing the engine doesn't have that problem so it might be a good idea, giving it a try
I'm unable to pass in engine, tried
engine: HttpClientEngine
, but then it won't accept
Apache
because of type mismatch
d

Dominaezzz

08/29/2019, 12:10 PM
You can pass
Apache.create {}
e

eirikb

08/29/2019, 12:14 PM
Nice, then I can do
engine : HttpClientEngine = Apache.create()
in ctor, and to create
MockEngine
I can do
MockEngine.create { addHandler { ... } }
and pass that in ctor. Thanks!