Five core assertions cover almost every test you'll write. The reference is up top — the quiz below tests whether you can pick the right one for each scenario.
assertEquals(expected, actual)
Compare two values for equality. Works for ints, doubles, Strings, anything with .equals().
assertEquals(8.5, employee.getHoursWorked());
assertNotEquals(expected, actual)
The opposite of assertEquals — passes when the two values are different. Used less often.
assertNotEquals(0.0, account.getBalance());
assertTrue(booleanValue)
For boolean checks. Pass it the boolean expression you expect to be true.
assertTrue(room.isOccupied());
assertFalse(booleanValue)
The opposite of assertTrue. Pass it the boolean expression you expect to be false.
assertFalse(room.isDirty());
assertArrayEquals(expectedArray, actualArray)
Compares the size and every element of two arrays. Don't use assertEquals on arrays — it compares object identity, which fails even when contents match.
assertArrayEquals(new int[]{1, 2, 3}, calculator.getDigits());