Insert assertions into the program source.
Make the assumptions of the code explicit.
The questions answered depend on the assertion used. Common assertions answer these questions:
Which procedures are getting unexpected input values?
Which procedures are returning unexpected output values?
Which local variables are getting assigned unexpected input values?
Some assertions can be costly to test. Others that are made in frequently executed functions may be costly in the aggregate.
Some programmers don’t like having users see assertions print if a problem occurs. You must assess which of two options will cause more trouble for the user: Your program can continue execution in a known error state, or it can terminate the application and print a message that won’t be of much help to the user.
You must be careful not to include any code that has side effects inside of the assertion expression. If you have such code and you turn assertion checking off, you will change the behavior of the program.
Make assertions preprocessor macros instead of procedures so they can be eliminated by redefining the macro.
Distinguish between fatal and nonfatal assumptions that are being violated. Report the nonfatal ones, but continue processing, possibly after remedying the problem.
Do a complete test run, with all assertions active, at least once before the program is put into production.