Jump to content

Test stub: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Licriss (talk | contribs)
m Example: minor clarity improvements in some phrasing and linking to test harness instead of attempting to summarise it
Move general info to test double
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{More citations needed|date=February 2021}}
{{More citations needed|date=February 2021}}
A '''test stub''' is a [[test double]] that provides static values to the software under test.
In [[software testing]], '''test stubs''' are programs that simulate the behaviours of software components (or modules) that a module undergoing tests depends on. Test stubs provide [[Canned_response|canned answers]] to calls made during the test, usually not responding at all to anything outside what's programmed in for the test.<ref>Fowler, Martin (2007), ''Mocks Aren't Stubs'' [http://martinfowler.com/articles/mocksArentStubs.html#TheDifferenceBetweenMocksAndStubs (Online)]</ref> They are mainly used in incremental testing's [[top-down approach]]. Stubs are computer programs that act as temporary replacement for a called basin module and give the same output as the actual product or software.


A test stub provides [[Canned_response|canned answers]] to calls made during the test, usually not responding at all to anything outside what's programmed in for the test.<ref>Fowler, Martin (2007), ''Mocks Aren't Stubs'' [http://martinfowler.com/articles/mocksArentStubs.html#TheDifferenceBetweenMocksAndStubs (Online)]</ref>
==Example==
Consider a computer program that queries a database to obtain the sum price total of all products stored in the database. In this example, the query is slow and consumes a large number of system resources. This reduces the number of test runs per day. Secondly, tests may include values outside those currently in the database. The method (or call) used to perform this is {{code|get_total()}}. For testing purposes, the source code in {{code|get_total()}} can be temporarily replaced with a simple statement that returns a specific value. This would be a test stub.


A stub may be [[source code|coded]] by hand or generated via a [[software tool|tool]].
Several testing frameworks are available, as is software that generates test stubs based on existing source code and testing requirements. Stubs and Drivers are two possible components of a [[test harness]].

Stubs and drivers both are dummy components and are only created for test purposes.

Stubs are used when a component or application is ready but other software that it connects to is not.

For example, in a situation where one has three different modules: Login, Home, User. Suppose login module is ready for test, but the two minor modules Home and User, which are called by Login module are not ready yet for testing. At this time, a piece of dummy code is written, which simulates the called methods of Home and User. These dummy pieces of code are the stubs.

On the other hand, Drivers are the ones, which are the "calling" programs. Drivers are used in bottom up testing approach. Drivers are dummy code, which is used when the sub modules are ready but the main module is still not ready.

Taking the same example as above. Suppose this time, the User and Home modules are ready, but the Login module is not ready to test. Now since Home and User return values from Login module, so a dummy piece of code is written, which simulates the Login module. This dummy code is then called Driver.


==See also==
==See also==

Latest revision as of 11:56, 4 May 2024

A test stub is a test double that provides static values to the software under test.

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]

A stub may be coded by hand or generated via a tool.

See also

[edit]

References

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