...

/

Assertions: assertNull() and assertNotNull()

Assertions: assertNull() and assertNotNull()

Learn about assertNull() and assertNotNull() methods in JUnit 5.

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 single Object to check.
  • For the assertNull(Object actual, String message) method, when the Object isn’t
...