...

/

assertNotNull() method

assertNotNull() method

This lesson demonstrates how to use assertNotNull() method in JUnit 5 to assert test conditions.

assertNotNull() method

Assertions API provide static assertNotNull() method. This method helps us in validating that particular object is not null. This method takes the actual value and checks whether it is null or not.

  • If the actual value is not null then test case will pass.
  • If the actual value is null then test case will fail.

There are basically three overloaded methods for assertNotNull:-

Press + to interact
public static void assertNotNull(Object actual)
public static void assertNotNull(Object actual, String message)
public static void assertNotNull(Object actual, Supplier<String> messageSupplier)
  1. assertNotNull(Object actual) - It assert whether actual value is not null.

  2. assertNotNull(Object actual, String message) - It assert whether actual value is not null. In case, if the actual value is null then test case will fail with the provided message.

  3. assertNotNull(Object actual, Supplier<String> messageSupplier) - It assert whether actual value is not null. In case, if the actual value is null then test case will fail with the ...

Access this course and 1400+ top-rated courses and projects.