Monday, April 20, 2009

Explain Stubs & Drivers.

Stubs - Software Testing

It is not possible to test a single function by itself; is it? It must be called by something (if it is not the main program) and it may have calls to other modules, which are not there as of now.

If a function includes calls to other modules, dummy procedures known as stubs can be written to satisfy those calls.

Stubs replace module that are subordinate (i.e. called by) to the component to be tested. Stubs usually print out a message to indicate that it is called properly. It must take suitable/proper arguments and must return an suitable value(s).

Stubs play a role in top-down integration testing.

double calculate_salary(double hours, double rate)
{
cout<<"Salary is:"
return(hours*rate);
}

The main program can be tested using this above code.


Drivers - Software Testing

Driver is the simple main program whose purpose is solely to call a procedure or function that is being tested. Drivers play a role in bottom-up integration testing.

A driver program to test a calculate_income_tax function may consist of limes like

cout<<"income tax on 25,0000 is";
cout<<calculate_income_tax(250000)<<"\n";

Also See:
Integration Testing