Assertions: assertSame() and assertNotSame()
Explore the use of assertSame and assertNotSame methods in JUnit 5 to check whether two object references point to the same instance or different instances. Understand how these assertions work with overloaded methods and how to apply them to write precise unit tests validating object identity.
We'll cover the following...
We'll cover the following...
The assertSame() method
The assertSame() method asserts that two Object variables refer to the same Object.
It has three overloaded methods.
- If the
actualandexpectedvalues refer to the sameObject, the test case passes. - If the
actualandexpectedvalues don’t refer to the sameObject, the test