Hello Apeksha, JUnit provides static methods in the Assert class to test for certain conditions. These assertion methods typically start with assert and allow you to specify the error message, the expected and the actual result. An assertion method compares the actual value returned by a test to the expected value, and throws an AssertionException if the comparison test fails. Following are some of these methods along with their descriptions:
-
fail(String): Let the method fail. Might be used to check that a certain part of the code is not reached. Or to have a failing test before the test code is implemented. The String parameter is optional.
-
assertTrue([message], boolean condition): Checks that the boolean condition is true.
-
assertFalse([message], boolean condition): Checks that the boolean condition is false.
-
assertEquals([String message], expected, actual): Tests that two values are the same. Note: for arrays the reference is checked, not the content of the arrays.
-
assertEquals([String message], expected, actual, tolerance): Test that float or double values match. The tolerance is the number of decimals which must be the same.
-
assertNull([message], object): Checks that the object is null.
-
assertNotNull([message], object): Checks that the object is not null.
-
assertSame([String], expected, actual): Checks that both variables refer to the same object.
-
assertNotSame([String], expected, actual): Checks that both variables refer to different objects.