3 ms·
Let'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 yo
by lpapez 3y ago
Let'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.