Skip to content
BENIBIX Learn

Test Double

Development🧪 Testing & QualityTest Doubles

Also known as Test Doubles, Fake Object

A stand-in that takes the place of a real part during a test.

Think of it like

Think of it like a stunt double in a film. It stands in for the real star.

Example

Jack's checkout test cannot charge a real card each run. He swaps the payment service for a test double that always says paid.

Why it matters

Tests stay fast, free and the same each time. That holds even when the real part is slow or out of your hands.

Definition

A test double is a stand-in that replaces a real part of the system during a test. You use one when the real thing is slow, costs money or is hard to control. A payment service, an email sender and the clock are common things to swap out. Mocks, stubs, fakes and spies are all kinds of test double. The name comes from a stunt double in films.

Common mistake

Replacing so much with doubles that the test only checks the doubles. Keep some tests that use the real parts.

Key takeaways

  1. 1
    A stand-in. For a real part.
  2. 2
    For slow or costly parts. Payments, email, the clock.
  3. 3
    Several kinds. Mock, stub, fake, spy.