Skip to main content

Posts

Showing posts from March, 2022

assertTrue vs assertEquals for text verification

   We all do text validation in our automation tests to validate whether the returned value is the same as the expected one or not. I see that many folks use the assertTrue command instead of assertEquals to validate the returned text while using assertions from TestNG or JUnit. Let's see why using assertTrue is bad practice for text comparison.   assertEquals public static void assertEquals(String actual, String expected) Asserts that two Strings are equal. If they are not, an AssertionError is thrown. Parameters: actual - the actual value expected - the expected value assertTrue public static void assertTrue(boolean condition) Asserts that a condition is true. If it isn't, an AssertionError is thrown. Parameters: condition - the condition to evaluate   Let’s say that I have an automated test script where I would like to verify the Title of the home page -  we are doing the check using assertTrue as well as assertEquals methods.   String Exp