Chapter 5. Interaction Testing
Testing how the code-under-test deals with collaborators by using mock and stub test doubles is called interaction testing. This is one of the most misunderstood and abused techniques in automated testing. Inappropriate use of mocks and stubs can tightly couple your test code to the implementation details, causing brittle tests and making refactoring difficult because changes in how a unit works can break tests, even though the behavior is still correct. At the same time, mocks and stubs can enable a modular design that uses Inversion of Control (IoC) to define the relationships between units resulting in loosely coupled code that cooperates through well-defined interfaces.
Get Spock: Up and Running 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.