Posts

Showing posts from May, 2018

Test Doubles by Example

Image
Test Doubles are replacements of inconvenient dependencies. When properly used, they help to keep your tests focused, fast, readable and stable. They also come with risks like increased test setup complexity, increased coupling to implementation details or even partial replacement of the actual functionality under test. For a positive impact on the test suite, make sure your team has guidelines on when and how to use test doubles. Test doubles are usually introduced when the dependency is: Unpredictable: real database, current time Unavailable: web service Slow: real database, web service Asynchronous: message brokers, mail servers Expensive to use: setting up browsers, web services Has no test version: third-party service Lives in another application layer: layered architecture Internal, even in the same layer, but we want to write Solitary Unit Tests Types of test doubles demonstrated by the sample project in this post are: Dummy = Irrelevant arguments Stub = Fi