Jump to content

Test double

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 98.216.104.172 (talk) at 00:43, 1 August 2016 (Types of test doubles: Added link to another kind of test double, verified fake.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In computer programming and computer science, especially in object-oriented programming, programmers and developers employ a technique called automated unit testing to enhance the quality of the software. Frequently, the final release software consists of a complex set of objects or procedures interacting together to create the final result. In automated unit testing, it may be necessary to use objects or procedures that look and behave like their release-intended counterparts, but are actually simplified versions that reduce the complexity and facilitate testing. A test double is a generic (meta) term used for these objects or procedures.

Types of test doubles

Gerard Meszaros[1] identified several different terms for what he calls, "Test Doubles." Using his vocabulary, there are at least five types of Test Doubles:

  • Test stub (used for providing the tested code with "indirect input")
  • Mock object (used for verifying "indirect output" of the tested code, by first defining the expectations before the tested code is executed)
  • Test spy (used for verifying "indirect output" of the tested code, by asserting the expectations afterwards, without having defined the expectations before the tested code is executed)
  • Fake object (used as a simpler implementation, e.g. using an in-memory database in the tests instead of doing real database access)
  • Dummy object (used when a parameter is needed for the tested method but without actually needing to use the parameter)

Another form of test double is the Verified Fake, a Fake object whose behavior has been verified to match that of the real object using a set of tests that run against both the Verified Fake and the real implementation.[2]

While there is no open standard for test double and the various types, there is momentum for continued use of these terms in this manner. Martin Fowler used these terms in his article, Mocks Aren't Stubs[3] referring to Meszaros' book. Microsoft also used the same terms and definitions in an article titled, Exploring The Continuum Of Test Doubles.[4]

See also

References

  1. ^ Meszaros, Gerard (2007). xUnit Test Patterns: Refactoring Test Code. Addison-Wesley. ISBN 978-0-13-149505-0.
  2. ^ Turner-Trauring, Itamar (2016). "Write test doubles you can trust using verified fakes". Retrieved 2016-07-31.
  3. ^ Fowler, Martin (2007). "Mocks Aren't Stubs". Retrieved 2010-12-29.
  4. ^ Seemann, Mark (2007). "Exploring The Continuum Of Test Doubles". Retrieved 2010-12-29.

Gerard Meszaros:

Martin Fowler: