Assertions

The part that says what a test checks. A test without an assertion passes whatever the code does, and one assertion per test is the habit this part builds: assertEquals over integers, strings and objects, with the order of the two arguments and the failure line it prints when they differ, then the delta overload for a double, where 0.1 + 0.2 is not 0.3. assertTrue, assertFalse, assertNull and assertNotNull carry a message that says what the reader should have seen, and the array, list and map assertions compare a whole collection. The part closes with assertAll, which runs every assertion and reports each failure instead of stopping at the first.

2.1 assertEquals integers, strings and objects, the order of the arguments, the failure line Open 2.2 Floating point and delta assertEquals with a delta, 0.1 + 0.2, the exact overload Open 2.3 true, false, null and a message assertTrue, assertFalse, assertNull, assertNotNull, the message Open 2.4 Arrays, lists and maps assertArrayEquals, a List, a Map, the one element that differs Open 2.5 assertAll every assertion runs, the report lists every failure, the difference from separate methods Open

Lessons