The org.testng.Assert class provides various assertion methods for verifying the expected and actual results in TestNG test cases. The assertSame() method checks if two objects refer to the same java object in memory. If both objects are referring to the same object, the test will pass, otherwise it will fail.
Example: Suppose we have two objects of the same class, obj1 and obj2. We want to check if they refer to the same object in memory using assertSame() method.
@Test public void testAssertSame() { Object obj1 = new Object(); Object obj2 = obj1;
Assert.assertSame(obj1, obj2, "Both objects are not the same."); } }
In this example, we have imported org.testng.Assert package and used assertSame() method to check if obj1 and obj2 are referring to the same object. We have passed three parameters to the assertSame() method, first two parameters are objects that we want to compare and the third parameter is an optional message that will be displayed if the test fails.
Package library: This method is a part of TestNG library which is usually added to the classpath through Maven dependencies. The package location is "org.testng.Assert".
Java Assert.assertSame - 30 examples found. These are the top rated real world Java examples of org.testng.Assert.assertSame extracted from open source projects. You can rate examples to help us improve the quality of examples.