26 ms·
I dont want to tell others how to write code, but if you need to provide a rest api mock to test more than just the thing that does requests, your code could li
by lionkor 3y ago
I dont want to tell others how to write code, but if you need to provide a rest api mock to test more than just the thing that does requests, your code could likely be improved a lot by decoupling things.
- Hamuko 3y agoHow is my code going to be improved by it outside of writing tests?
- lpapez 3y agoLet's say you are making a feature which will call into an external API, send an email based on the response and then also write something to the DB. How do you ensure this actually works and for example emailing isn't broken accidentaly by a future refactor? Of course that you can and should test each individual component in this scenario, but at some point you need to mock more than "the thing that does requests" and check if it click with other components.
- zaphar 3y agoI would argue that when you are at the point of testing that the actual api works as you expect what you need is an integration test not a unit test. And you shouldn't mock it because if you mock it you won't actually be testing what you wanted to test. For unit tests use a Fake for anything that interacts with an external system.