Mocking – Removing External Dependencies

"Talk is cheap. Show me the code."
– Linus Torvalds

TDD is about speed. We want to quickly demonstrate whether an idea, concept, or implementation is valid or not. Further on, we want to run all tests quickly. A major bottleneck to this speed is external dependencies. Setting up the DB data required by tests can be time-consuming. The execution of tests that verify code that uses third-party APIs can be slow. Most importantly, writing tests that satisfy all external dependencies can become too complicated to be worthwhile. Mocking both external and internal dependencies helps us solve these problems.

We'll build on what we did in Chapter 3, Red-Green-Refactor – From Failure Through Success until Perfection ...

Get Test-Driven Java Development - Second Edition 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.