User Tools

Site Tools


test_doubles

This is an old revision of the document!


Table of Contents

Sources:

  1. Software Testing course at ITMO university by Kochubeev Nikolay Sergeevich

Test doubles

Test doubles are used in unit tests to mimic the real objects the tests depend on.

There are several test doubles types:

  • dummy;
  • stub;
  • fake;
  • spy;
  • mock.

Dummy

Dummy is an object that's not actually used in the test. It is used as a placeholder, for example, when there needs a certain type of object to be passed as a parameter to initialize a method.

Stub

Stubs provide predetermined responses. They're used to isolate the behavior of the component from its dependencies. They're typically used to simulate the behavior of complex or external components (data bases, web services, external API).

Fake

A fake is a simplified real object. They're used for tests that require a real implementation but a lighter and faster one.

Spy

Spies record information about how they were interacted with during the test (how many times was the method called, what arguments were passed, the order of method calls).

Mock

Mocks are used to verify that certain interactions took place by being pre-programmed to expect certain specification of the calls.

test_doubles.1757443504.txt.gz · Last modified: by plida