Why mocking is a bad idea
cs-syd.eu
cs-syd.eu
Testing, and testing with mocks especially, is not about proving your code works when things are right. It's about proving your code fails properly when things are wrong. If you're not hunting down cases where things fail then you're not testing well enough.
The extra work required to properly separate concerns near to a foreign API surface, in my experience, pays for itself: you expected (and wrote tests for) three outcomes, and provided an observability hook for those outcomes, but a fourth raises its ugly head in real life, forcing you to revisit the API docs and add it to your mock. You add references to the API doc relative to those outcomes, and your code can be easily followed and troubleshooted by the next person. What's not to like?
I feel as if I've seen the same arguments raised over and over against mocks, all of which fall back to "I'm too lazy to maintain the state-space of unit tests", which is, quite frankly, not my problem–it's yours. Grow up and be responsible.