Assertion properties commonly fall into one of these three categories:
- Preconditions that a property holds before a code block executes
- Postconditions that a property holds after a code block executes
- Invariants that a property holds before and after a code block executes
Note: Assertions are disabled on runtime by default, to enable them you must use the -debug flag
Programming assertions
Constructors: assert booleanExpression; assert booleanExpression : message; Sample: assert time>12 : "The value of time must be greater than 12. Time is +"time; The use of assertion programming can be adopted slowly. Use assertions first around the entry points of functions or methods. Then move on to conditions executed within the code before advancing to manipulations and function returns. As you increase the usage of assertions, the quality of the code will improve.