Jump to content

Test stub: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m software program → computer program: change indefinite term to concrete (x2)
Dougher (talk | contribs)
m fix capitalization, rewording
Line 1: Line 1:
In computer science, '''test stubs''' are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.
In computer science, '''test stubs''' are programs which simulate the behaviors of software components (or modules) that are depended-upon modules of the module being tested.


{{cquote|Test stubs provide 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>}}
{{cquote|Test stubs provide 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>}}


Test Stubs are mainly used in incremental testing's Top-Down approach. Stubs are computer programs which act as a module and give the output as given by an actual product/software.
Test stubs are mainly used in incremental testing's Top-Down approach. Stubs are computer programs which act as temporary replacement for a called module and give the same output as the actual product/software.
Test stub is also called as a 'called' function.


==Example==
==Example==
Consider a computer program which queries a database to obtain the sum price total of all products stored in the database. However, the query is slow and consumes a large number of system resources. This reduces the number of test runs per day. Secondly, the tests need to be conducted on values larger than what is currently in the database.
Consider a computer program which queries a database to obtain the sum price total of all products stored in the database. However, the query is slow and consumes a large number of system resources. This reduces the number of test runs per day. Secondly, the tests may need to be conducted on values outside those which are currently in the database.


The method (or call) used to perform this is ''get_total()''. For testing purposes, the source code in ''get_total()'' could be temporarily replaced with a simple statement which returned a specific value. This would be a test stub.
The method (or call) used to perform this is ''get_total()''. For testing purposes, the source code in ''get_total()'' could be temporarily replaced with a simple statement which returned a specific value. This would be a test stub.

Revision as of 01:35, 14 June 2013

In computer science, test stubs are programs which simulate the behaviors of software components (or modules) that are depended-upon modules of the module being tested.

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

Test stubs are mainly used in incremental testing's Top-Down approach. Stubs are computer programs which act as temporary replacement for a called module and give the same output as the actual product/software.

Example

Consider a computer program which queries a database to obtain the sum price total of all products stored in the database. However, the query is slow and consumes a large number of system resources. This reduces the number of test runs per day. Secondly, the tests may need to be conducted on values outside those which are currently in the database.

The method (or call) used to perform this is get_total(). For testing purposes, the source code in get_total() could be temporarily replaced with a simple statement which returned a specific value. This would be a test stub.

There are several testing frameworks available and there is software that can generate test stubs based on existing source code and testing requirements.

See also

References

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