Skip to main content
Logo image

Section 19.7 Top-Down Testing

Sometimes you might want to test the flow of control of a program, but you haven’t written all of your functions yet.
In this situation we use something called a stub. A stub is a skeleton function that consists of header info (comments), tracing messages (printf()) and assignment of output parameters (but not necessarily the actual values).
Example:
Suppose you wanted to check the flow of our fraction calculator, but you haven’t written the simplify() function yet. So here is what you could write instead of your simplify function:
/* *********************** STUB *************************
* given a fraction numer/denom determine a simplified
* fraction and return as output parameters
****************************************************** */
int simplify(int *numer, int *denom) {
  printf("Entering simplify() with %d/%d\n", *numer, *denom);
  *numer = *numer; /* not really neccessary, is it */
  *denom = *denom;
  printf("Exiting simplify() with %d/%d\n", *numer, *denom);
  return 0;
}
Eventually you’ll replace this stub with the real function.