Example showing different ways to assert a text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.testng.Assert.assertEquals; | |
import static org.testng.Assert.assertTrue; | |
import org.apache.commons.lang3.StringUtils; | |
import org.testng.annotations.Test; | |
public class AssertionTest { | |
public static final String ACTUAL = "text wrong here"; | |
public static final String EXPECTED = "text right here"; | |
// not recommended | |
@Test | |
public void usingAssertTrue() { | |
assertTrue(ACTUAL.equals(EXPECTED)); | |
} | |
// best one | |
@Test | |
public void usingAssertEqual() { | |
assertEquals(ACTUAL, EXPECTED); | |
} | |
// not recommended | |
@Test | |
public void usingAssertTrueAndStringUtils() { | |
assertTrue(StringUtils.equals(ACTUAL, EXPECTED)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results
usingAssertTrue
The problem here is: the error is not clear as the differences are true or false
usingAssertEqual
The good point here is: the error is clear and shows the text differences
usingAssertTrueAndStringUtils
The problem here is: the error is not clear as the differences are true or false