Assertions: assertNull() and assertNotNull()
Learn about assertNull() and assertNotNull() methods in JUnit 5.
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:
Press + to interact
public static void assertNull(Object actual)public static void assertNull(Object actual, String message)public static void assertNull(Object actual, Supplier<String> messageSupplier)
- 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
Ask