O'Reilly logo

Test-Driven Development with Mockito by Sujoy Acharya

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 5. Test Doubles

We know about stunt doubles—a trained replacement used for dangerous action sequences in movies, like jumping out of the Empire State Building, a fight sequence on top of a burning train, jumping from an airplane, or similar actions, mainly fight scenes. Stunt doubles are used to protect the elite real actors or when the actor is not available.

Similarly, sometimes it is not possible to unit test a code because of the unavailability of collaborator objects or the cost of instantiation for the collaborator.

If a code is dependent on database access, it is not possible to unit test the code unless the database is available, or if my code needs to send information to a printer and my machine is not connected to LAN.

Test doubles ...

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