Assertion Definition

Assertion

Assertion is the kind of statement through which it is stated that the predicate (logical expression) in some code, under any conditions, can have a true value. The predicate that verifies these assertions is evaluated at the time of program execution, and if it is false, the program is intentionally brought to a stop or an exception is raised.

An assertion can help in making the code more readable, aid the compiler when building the code, or even in defect identification of the program. In some languages like Eiffel, they form a part of the design process, and in others like C and Java, they are there for checking at runtime, assumptions.

They can, in most languages, be switched on and off at a time globally. They are usually enabled during development and disabled during final testing and release to the client. This is a good way not to incur the cost of evaluating the assertions, and it can actually ensure that in an abnormal condition a program that in a normal case would have been halted continues. This actually sometimes is preferred.