Assertions: assertNull() and assertNotNull()
Explore how JUnit 5's assertNull and assertNotNull methods help verify whether objects are null or not. Understand their overloads with optional failure messages, including message suppliers, to write precise unit tests.
We'll cover the following...
We'll cover the following...
The assertNull() method
The assertNull() method asserts that the given Object is null.
- If the actual value is
null, the test case passes. - If the actual value is
not null, the test case fails.
It has three different overloaded methods:
- The
assertNull(Object actual)method is the simplest form that only accepts a singleObjectto check. - For the
assertNull(Object actual, String message)method, when theObjectisn’t