Your SlideShare is downloading. ×
  • Like
Introduction to Test Doubles
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Introduction to Test Doubles


Slides used on my Online Training Class on Test Doubles

Slides used on my Online Training Class on Test Doubles

Published in Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Test Doubles The idea of test double comes from the “stunt doubles” that take the place of the actors in action movies. Source: xUnit Patterns, G. Meszaros
  • 2. Types of doubles These are used in Unit Tests: ● ● ● ● Test Stub Test Spy Mock Object Test Dummy
  • 3. The SUT and the double SUT: System Under Test (sometimes also called Subject Under Test) DOC: Depended-on Component ● ● We don't tests the doubles, we test/design the SUT ! Doubles are just the context, the dependencies
  • 4. Stub “To get good enough control over the indirect inputs of the SUT, we may have to replace some of the context with something we can control, a Test Stub” - ● ● Stubs can't remember calls Just return programmed answers
  • 5. Spy “To get good enough visibility of the indirect outputs of the SUT, we may have to replace some of the context with something we can use to capture these outputs of the SUT”. ● ● Spies remember calls, observ silently Don't have any expectations
  • 6. Mock “In other cases, we must peer inside the SUT to be able to determine whether the expected behavior has occurred”. ● ● ● Mocks expect certain calls to happen They fail if anything else happen They fail if expectations are not met
  • 7. The problem with word “Mock” In English, all these doubles are mocks (as in mock chicken meat, the one made from gluten or soya). This is why some frameworks use the word “mock” even when they really use spies. That is the case of “mockito”. ● Understand the concepts beyond the names used by frameworks.
  • 8. Isolation frameworks There are tools that allow us to stub out parts of the system even when the design doesn't allow for dependency injection. Let us test things that are apparently untestable. Example: Replacing the system funtion that gets the current Date and Time.