My opinion about the best way to use mock objects changes every few months. I’ll try some mocks, they’ll work well, I’ll start using more mocks, they’ll start getting in the way, I’ll back off, and then I’ll think, “Let’s try some mocks.” This cycle has been going for years and I have no reason to think it’s going to change anytime soon.
That said, some guidelines always hold true.
Don’t mock what you don’t own. In other words, use test doubles only to replace methods that are actually part of your application, and not part of an external framework. (Note that we violated this rule in this chapter when we stubbed ActiveRecord methods like update_attributes.)
|Prescription 19||Don’t mock what you don’t own.|
One reason ...