SoftAssert in TestNG example

testng soft assert example

SoftAssert in TestNG helps to collect all the assertions throughout the @Test method. And to see assertions result at the end of the test, we have to invoke assertAll().

SoftAssert don't throw an exception when an assert fails. The test execution will continue with the next step after the assert statement.

If we use normal asserts like Assert.assertTrue() or Assert.assertEquals() in TestNG, @Test Method will immediately fail after any of the Asserts fails.

Assertions in TestNG

What is Assertion????
Asserts helps us to verify the conditions of the test and decide whether test has failed or passed. A test is considered successful ONLY if it is completed without throwing any exception. There is a difference between SoftAssert and Hard Assert.

Let us focus more on using Assertions (Hard assert). Also check SoftAssert example in TestNG for more details on soft asserts.