3 ms·
The 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.
by pyrale 3y ago
The 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.