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.

Get Scala Test-Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.