How would you go about mocking a library class that has no interface, i. e. HttpClient of ktor?
i
ian.shaun.thomas
07/03/2023, 2:45 PM
You probably shouldn't. Use integration tests and for unit tests, abstract your network calls to interfaces that allow you to mock.
ian.shaun.thomas
07/03/2023, 2:47 PM
I believe ktor has some testing tools though but again I would try to avoid going that route.
d
Daniel Weidensdörfer
07/03/2023, 3:01 PM
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
romainbsl
07/06/2023, 6:48 AM
In that regards you should be using a Ktor instance with a MockEngine. MockMP does not fit here.