Summary
There is a love-hate relationship between developers and mock objects. On the one hand, there are obvious benefits of being able to test classes in isolation. This also evolves into a more loosely coupled architecture and there is greater reusability of code.
On other hand, mocks couple the test code to the actual implementation of the class being tested. If the test code undergoes some major refactoring, it might result in changes in the expectations and verifications of the mocks in the test. This deviates from the principle of the segregation of test and application code.
A mocking framework is a great tool in your development arsenal if rightly used. There is definitely such a thing as too much mocking, so steer clear away from it.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access