O'Reilly logo

Test-Driven Java Development by Alex Garcia, Viktor Farcic

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Mocking – Removing External Dependencies

 

"Talk is cheap. Show me the code."

 
 --Linus Torvalds

TDD is about speed. We want to quickly demonstrate whether some idea, concept, or implementation, is valid or not. Further on, we want to run all tests fast. A major bottleneck to this speed is external dependencies. Setting up DB data required by tests can be time-consuming. The execution of tests that verify code that uses third-party API 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required