3 ms·
Reimplementing a whole complex API with mocks is not exactly quick or easy or less error prone than the code that should interact with that API.
by tsimionescu 3y ago
Reimplementing a whole complex API with mocks is not exactly quick or easy or less error prone than the code that should interact with that API.
- lexicality 3y agoif your test implements a whole complex API then it's not a unit test
- MoreQARespect 3y agoIt can be fairly quick with tools like mitmproxy.
- pyrale 3y agoThe point of mocking is not to reimplement a service you depend on, it is to provide the answer that service would give in the specific example you're testing.
- zabzonk 3y agobut suppose that service could give all sorts of different responses, depending on (say) the time of day and the country originating the request.
- pyrale 3y agoWhat's relevant to you is your element under test, not the dependency. Does the component you're testing have a different behaviour for each different response? If yes, you're out of luck (but also, maybe you should split it in multiple components). If not, then you probably don't need to test every possible response the dependency returns.
- 8n4vidtmkvmk 3y agoYou're not out of luck. Your testing framework should allow you to hardcode different responses to different requests. Include the time in the response if you need to, it shouldn't be hard. I've started adding random elements to my mock responses to force other developers to not assert things that aren't relevant to the test.