Jump to content

Test stub

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Stevebroshar (talk | contribs) at 11:38, 4 May 2024 (Tighten wording; this is not about drivers). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A test stub is a software testing test double that provides static values to the software under test via a well-defined interface so that a test can run without the production code that normally implements the interface.

A test stub provides canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test.[1]

Several testing frameworks are available, as is software that generates test stubs based on existing source code and testing requirements.

Stubs and drivers are used to build test harness.

Uses

As with all test doubles, a stub may be used to simplify and speed test execution.

For example, a program that uses a database server is relatively slow and consumes significant system resources – which impedes testing productivity. Also, a test case might require values outside those stored in the database. For testing, the source code that provides the value could be a stub that returns a specific value instead of accessing the database.

As with all test doubles, a stub may be used to test part of the system that is ready for testing even if its dependencies are not.

For example, in a system with modules Login, Home and User, suppose Login is ready for test, but the other two are not. The consumed functions of Home and User can be stubbed so that Login can be tested.

See also

References

  1. ^ Fowler, Martin (2007), Mocks Aren't Stubs (Online)