Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example showing different ways to assert a text
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));
}
}
@eliasnogueira

This comment has been minimized.

Copy link
Owner Author

eliasnogueira commented Mar 16, 2020

Results

usingAssertTrue

The problem here is: the error is not clear as the differences are true or false

java.lang.AssertionError: expected [true] but found [false]
Expected :true
Actual   :false

usingAssertEqual

The good point here is: the error is clear and shows the text differences

java.lang.AssertionError: expected [text right here] but found [text wrong here]
Expected :text right here
Actual   :text wrong here

usingAssertTrueAndStringUtils

The problem here is: the error is not clear as the differences are true or false

java.lang.AssertionError: expected [true] but found [false]
Expected :true
Actual   :false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.