Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mocks and Stubs and Spies, oh my!

Brian Gardner
November 05, 2017

Mocks and Stubs and Spies, oh my!

Introduction to test doubles. What they are, how they're different, and where they're used.

Brian Gardner

November 05, 2017
Tweet

More Decks by Brian Gardner

Other Decks in Technology

Transcript

  1. When to use Test Doubles? • System under test has

    indirect inputs • System under test has indirect outputs • Slow tests*
  2. What is a mock? • Configured with expected method calls

    and parameters • Verifies method calls itself • Can return values for method calls (secondary)
  3. What is a Stub? • Returns values you specify in

    test • Can not return anything not specified • Does not record number of interactions
  4. What is a Spy? • Mock + Stub • Returns

    values based on test configuration • Records method calls or other information • Allows you to verify method calls and parameters
  5. What is a Dummy? • Never actually used in a

    test • Just fills the parameter list
  6. What is a Fake? • Real object specifically for test

    • Replaces an object in test with a simpler/faster implementation
  7. Recap • Use correct terms for more effective communication •

    Match test doubles to the appropriate tests • Don’t over use them