'How to use OR condition with TestNG assertions
Is there a way to do assertions with OR
with TestNG?
This is what I am trying to find:
assertEquals(expected, value1 || value2); // Can be any number of values.
Solution 1:[1]
You could make a very simple wrapper around the TestNG code:
private void assertContains(Object actual, Object ... expected) {
assertTrue(Arrays.asList(expected).contains(actual));
}
I briefly looked through the TestNG source code and didn't see any methods similar to the method above, but I am not very familiar with the TestNG patterns.
Solution 2:[2]
I just did a workaround with boolean assertions:
if(condition1 || condition2){
Assert.assertTrue(true)
} else {
Assert.fail("Your Explanation here")
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Carl Mastrangelo |
Solution 2 | Ricardo De Leon |