...

/

assertSame() method

assertSame() method

This lesson demonstrates how to use assertSame method in JUnit 5 to assert test conditions.

We'll cover the following...

assertSame() method

Assertions API provide static assertSame() method. This method helps us in validating that expected and actualrefer to the exact same object. JUnit uses == operator to perform this assert.

  • If the actual and expected value refers to the same object then the test case will pass.
  • If the actual and expected value does not refer to the same object then the test case will fail.

There are basically three useful overloaded methods for assertSame:-

Press + to interact
public static void assertSame(Object expected, Object actual)
public static void assertSame(Object expected, Object actual, String message)
public static void assertSame(Object expected, Object actual, Supplier<String> messageSupplier)
...
Access this course and 1400+ top-rated courses and projects.