|
|
 |
|
 |
|
|
Stub A dummy function that assists in testing part of a program. A stub has the same name and interface as a function that actually would be called by the part of the program being tested, but it is usually much simpler. |
|
|
|
|
|
|
|
|
A stub can also be used to print the set of values that are passed to it; this tells us whether or not the module under test is supplying the proper information. Sometimes the stub will assign new values to its reference parameters to simulate data being read or results being computed to give the module something to keep working on. Because we can choose the values that are returned by the stub, we have better control over the conditions of the test run. |
|
|
|
|
|
|
|
|
Here is a stub that simulates function PrintName in the Transpose program. |
|
|
|
|
|
|
|
|
void PrintName( /* in */ char ch ) // First character of last name
// Stub for function PrintName in the Transpose program
{
cout << PrintName was called with ch = << ch << endl;
} |
|
|
|
|
|
|
|
|
Here is a stub that simulates a call to FindLast by returning an arbitrarily chosen character. |
|
|
|
|
|
|
|
|
void FindLast( /* out */ char& ch ) // First character of last name
// Stub for function FindLast in the Transpose program
{
cout << FindLast was called here. Returning X. << endl;
ch = X;
} |
|
|
|
|
|
|
|
|
Each of these stubs is simpler than the function it simulates, which is typical because the object of using stubs is to provide a simple, predictable environment for testing a module. |
|
|
|
|
|
|
|
|
In addition to supplying a stub for each call within the module, you must provide a dummy programa driverto call the module itself. A driver program contains the bare minimum of code required to call the module being tested. |
|
|
|
|
|