An assertion is a function that validates a condition; if the condition is not valid, it throws an error that causes the test to fail. A test method can include one or more assertions; all the assertions have to pass in order to have the test method pass. In the first JSTD test example, we have used the assertEquals
and assertException
assertions. In this section, the other different built-in assertions provided by JSTD will be illustrated.
The
assert
and assertTrue
assertions do the same thing; they have two parameters. The first parameter is an optional message to be displayed if the assertion fails, and the second parameter represents an expression. The assert
and assertTrue
assertions are passed if the expression parameter is evaluated to true
. The
assertFalse
assertion does the reverse operation; it passes if the expression is evaluated to false. For example, the following assertions work:
assert(6 =...