Chapter 23Test Double Patterns

Patterns in This Chapter

Test Double 522

Test Double Usage

      Test Stub 529

      Test Spy 538

      Mock Object 544

      Fake Object 551

Test Double Construction

      Configurable Test Double 558

      Hard-Coded Test Double 568

Test-Specific Subclass 579

Test Double

Also known as


How can we verify logic independently when code it depends on is unusable?How can we avoid Slow Tests?

We replace a component on which the SUT depends with a "test-specific equivalent."


Sometimes it is just plain hard to test the SUT because it depends on other components that cannot be used in the test environment. Such ...

Get xUnit Test Patterns: Refactoring Test Code now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.