Monday, October 15, 2007

Drivers and Stubs

It is always a good idea to develop and test software in "pieces". But, it may seem impossible because it is hard to imagine how you can test one "piece" if the other "pieces" that it uses have not yet been developed (and vice versa). To solve this kindof diffcult problems we use stubs and drivers.

In white-box testing, we must run the code with predetermined input and check to make sure that the code produces predetermined outputs. Often testers write stubs and drivers for white-box testing.

Driver for Testing:

Driver is a the piece of code that passes test cases to another piece of code. Test Harness or a test driver is supporting code and data used to provide an environment for testing part of a system in isolation. It can be called as as a software module which is used to invoke a module under test and provide test inputs, control and, monitor execution, and report test results or most simplistically a line of code that calls a method and passes that method a value.

For example, if you wanted to move a fighter on the game, the driver code would be
moveFighter(Fighter, LocationX, LocationY);

This driver code would likely be called from the main method. A white-box test case would execute this driver line of code and check "fighter.getPosition()" to make sure the player is now on the expected cell on the board.

Stubs for Testing:

A Stub is a dummy procedure, module or unit that stands in for an unfinished portion of a system.

Four basic types of Stubs for Top-Down Testing are:

1 Display a trace message
2 Display parameter value(s)
3 Return a value from a table
4 Return table value selected by parameter

A stub is a computer program which is used as a substitute for the body of a software module that is or will be defined elsewhere or a dummy component or object used to simulate the behavior of a real component until that component has been developed.

Ultimately, the dummy method would be completed with the proper program logic. However, developing the stub allows the programmer to call a method in the code being developed, even if the method does not yet have the desired behavior.

Stubs and drivers are often viewed as throwaway code. However, they do not have to be thrown away: Stubs can be "filled in" to form the actual method. Drivers can become automated test cases.

14 comments:

Meow said...

thnx a lot dear :)... i have so many other queris too related to testn,, wud post it else wud mail 2u ..

Meow said...
This comment has been removed by the author.
shrikant2002 said...

really thanx

zendprince said...

help me? What does the stub procedure include?

zendprince said...

What does the stub procedure include?
help me? Thk a lot

sandeep said...

well explained by amith.....

sunitha said...

synonym for drivers and stubs ?

rakesh singh said...

nw i knw the difference between tem....thnks a lot,explanation was very brief and clear!!

Unknown said...

thaks so much..

Unknown said...
This comment has been removed by the author.
neethu said...

Hi, probably our entry may be off topic but anyways, I have been surfing around your blog and it looks very professional. It’s obvious you know your topic and you appear fervent about it. I’m developing a fresh blog plus I’m struggling to make it look good, as well as offer the best quality content. I have learned much at your web site and also I anticipate alot more articles and will be coming back soon. Thanks you.





Software Testing Training Chennai

Unknown said...

Thank you...it was very helpful..i think i have been using them without knowing this!!!

Unknown said...

Explain the significance of stub and drivers with the help of example.

Unknown said...

Answer this question plz