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 argument(s) and must return a suitable value(s).
Stubs play a role in top-down integration testing.
double calculate_salary(double hours, double rate)
The main program can be tested using this above code.
Driver is a 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 lines like
cout<<”income tax on 25,0000 is”;
Top-down Strategy (this is advantageous if critical errors are suspected in the higher levels)
1. We first test the top layer/controlling subsystem.
2. Secondly we combine all the subsystems that are called by the tested subsystems and test the resulting collections of subsystems.
3. We will continue doing this until all subsystems are integrated into the test.
4. We will use test stubs to replicate (simulate) the components of lower layers that have not yet been integrated.
5. We do not need drivers.
Bottom-up Strategy (this is advantageous if critical errors are suspected in the lower levels)
1. We first individually test the subsystem in the lowest layer of call hierarchy.
2. We then integrate the next subsystems and test them from the next layer up that call the previously tested subsystems.
3. We do this repetitively till all subsystems are included in the testing.
4. In this case we use drivers to replicate (simulate) components of higher layers.
5. We do not need stubs in this case.