Thursday, September 25, 2008

Stubs and Drivers in Software Testing

Stub in software development is a piece of code used to stand in some other functionality.

A stub may simulate the behavior of the existing code (such as procedure on a remote machine) or a temporary substitute for yet-to-be-developed code.

Example

BEGIN

Temperature = ThermometerReadIn()

If Temperature > 40 THEN

PRINT “It’s Hot!”

ENDIF

END

BEGIN ThermometerReadIn()

RETURN 40

END ThermometerReadIn

The above pseudo code utilizes the function “ThermometerReadIn” that returns a temperature. While the function “ThermometerReadIn”, would be indented to read some hardware device, this function currently does not contain this function correctly does not contain the necessary code. So, “ThermometerReadIn” does not in essence, simulate any process, yet it does return a legal value, allowing the main program to be atleast partly tested.

Stubs are dummy modules that simulate the low level modules in the top approach

Drivers are the dummy modules that simulate the high level modules in the bottom-up approach

A Stub is a piece of code that simulates the activity of missing component.

A driver is a piece of code that passes test cases to another piece of code.

Stub is a skeleton of function having function header. This function can have actual simple statements which can be replaced with the actual code.

Driver is a small program used to test a function. Drivers are dummy lines of code, used in Bottom-up approach calling programs. Drivers helps to test the function which is being tested by the driver calls another function then that function is called stub.

For further reading:

Link1, Link2, Link3

No comments: