What is an Assert
From Software testing and development
Definition:
An “assert” statement asserts that it's condition must be true.
Undefined “Bad Things” happen if it is false.
There is a deliberate degree of fuzziness in this definition. The only thing clear is that the expression should be true.
What is not specified is...
- Whether the expression is evaluated.
- What exactly will happen if the expression is false.
- Whether the control flow exits out of the the assert.
- Whether they are even compiled into the code at all.
Rule 0
- You cannot rely on the condition being evaluated.
- You cannot rely on it to alter the control flow.
Corollary of Rule 0 . No Side Effects!
The assert expression should never have side-effects.
eg.
assert( n++ < 10); // NO! NO! NO!
[edit] Asserts are....
- Assertions are Sanity checks,
- Assertions are debug tools,
- Assertions are endo-tests. (Tests from inside).
- Assertions are an aid to writing correct software.
- Assertions validate the software itself, not the data fed to the software.
- Assertions document the assumptions and beliefs of the author.
- Assertions document the prerequisites and effects of software in a manner that is
- verifiable
- verified
- and up to date with the software itself.
[edit] An Assertion failure means...
- Your program has gone barking mad.
- Your program has a bug, is defective, incorrectly written or designed.
- The software is invalid, not the input data.
- The author made an invalid assumption, or had an incorrect belief.
- The only real fix is a new version of the software
[edit] An Assertion failure does NOT mean...
- The user has entered invalid data.
- A data link or store has corrupted the data.
- The hardware has failed.
- The user has failed to plug something in.
- The program / system is improperly configured.
Up: Asserts for Embedded Systems Next : What's so special about Embedded Systems
