How would you go about mocking a library class tha...
# kodein
d
How would you go about mocking a library class that has no interface, i. e. HttpClient of ktor?
i
You probably shouldn't. Use integration tests and for unit tests, abstract your network calls to interfaces that allow you to mock.
I believe ktor has some testing tools though but again I would try to avoid going that route.
d
Well I already use clean architecture with interfaces. In this case a DataSource calls HttpClient, now to check that it gets correctly called (request has POST method with xyz field, etc) I could write some tests. But maybe thats a bit overhead anyways 😄
r
In that regards you should be using a Ktor instance with a MockEngine. MockMP does not fit here.