I have two software components: My application and a library (which is owned by my company, but another team), which is used by the application. The library is a client library for some service and performs HTTP requests. The library also maps the HTTP response to the internal representation of the application. This is done by injecting a mapping class into the library by the application.
I already have unit tests for the mapping class and for the application, whereas the client library call is always mocked.
Now I'm thinking of integration test the library and I'm not sure what's the best way to do that:
Mock the library call and only check that it's called with the correct parameters
Mock only the HTTP call done by the library
Replace the HTTP call in the library with an in-memory fake (=dummy) implementation during testing
I'm in favor of the last point, but given that the internals of our library rarely changes, I'm not sure if a fake strategy is worth the effort.
What's your opinion on this? Can you think of another solution?
I would create helpers inside the library that would allow you to mock the HTTP response. Therefore, you'd see the code running inside the library and you could use the libraries that verify the JSON format to make sure that the http request/response is the one you're expecting.
In this sense, you're checking i) the library actually works with your system; ii) the processes the correct HTTP response; thus, your helper could be easy enough so that developers would only need to provide the content of the http response
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With