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

  • 563 views
Published

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

Views

Total Views
563
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
13
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 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 http://xunitpatterns.com/Test%20Double.html
  • 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” - http://xunitpatterns.com/Test%20Stub.html ● ● 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”. http://xunitpatterns.com/Test%20Spy.html ● ● 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”. http://xunitpatterns.com/Mock%20Object.html ● ● ● 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.