Assertions are methods that should check for a condition that could be evaluated and throw an exception if the condition is not met, thus aborting the execution of the test.
The JUnit API includes the class Assert
, which is the base class all of the test case classes. It holds several assertion methods useful for writing tests. These inherited methods test for a variety of conditions and are overloaded to support different parameter types. They can be grouped together in different sets, depending on the condition checked; for example:
assertEquals
assertFalse
assertNotNull
assertNotSame
assertNull
assertSame
assertTrue
fail
The condition tested is pretty obvious and easily identifiable by the method name. Perhaps the ones that deserve some attention are assertEquals()
and assertSame()
. The former when used on objects asserts that both objects passed as parameters are equal, calling the objects' equals()
method. The latter asserts that both objects refer to the...