There is a clear winner here! Lets explore which one is better.
Here is the scenario:
“Lets say I have to test if the appropriate tooltip is flashed for a component”
To get to the code directly, lets say I already have the tooltip text stored in a variable. Now all I have to do is to compare this string to the components tooltip text which I would get at runtime.
So the algorithm would be
We usually tend to use verifyTrue to compare because according to our algorithm we are expecting the result of the string comparison to be TRUE
There is nothing wrong in using verifyTrue as if your test passes there is no difference in using verifyTrue or verifyEquals. The actual difference comes into picture only when your test fails.
String varExpectedTooltipText = “Some tooltip”;
// Method 1 - verifyTrue(selenium.getAttribute("componentID"+"@title").equals(varExpectedTooltipText));
// Method 2 – verifyEquals(selenium.getAttribute("componentID"+"@title"), varExpectedTooltipText);
Log message when Method 1 fails:
java.lang.AssertionError: java.lang.AssertionError: null
Log message when Method 2 fails:
verifyEquals gives: java.lang.AssertionError: java.lang.AssertionError: Expected "Close this book list" but saw "Close this book lis" instead
Now you decide which one looks better – For me its verifyEquals wins the fight
Here is the scenario:
“Lets say I have to test if the appropriate tooltip is flashed for a component”
To get to the code directly, lets say I already have the tooltip text stored in a variable. Now all I have to do is to compare this string to the components tooltip text which I would get at runtime.
So the algorithm would be
- Have the Expected Tooltip text stored in a variable
- Get the Actual Tooltip text for the component
- Compare the two strings – you should get the exact text
We usually tend to use verifyTrue to compare because according to our algorithm we are expecting the result of the string comparison to be TRUE
There is nothing wrong in using verifyTrue as if your test passes there is no difference in using verifyTrue or verifyEquals. The actual difference comes into picture only when your test fails.
String varExpectedTooltipText = “Some tooltip”;
// Method 1 - verifyTrue(selenium.getAttribute("componentID"+"@title").equals(varExpectedTooltipText));
// Method 2 – verifyEquals(selenium.getAttribute("componentID"+"@title"), varExpectedTooltipText);
Log message when Method 1 fails:
java.lang.AssertionError: java.lang.AssertionError: null
Log message when Method 2 fails:
verifyEquals gives: java.lang.AssertionError: java.lang.AssertionError: Expected "Close this book list" but saw "Close this book lis" instead
Now you decide which one looks better – For me its verifyEquals wins the fight
Comments