Hard #assertion are used when you want to halt the execution of the test script (or test method) when the assert condition does not match with the expected result. #softassertion are used when the test script (or test method) need not be halted when the assertion condition does not meet the expected result. #testng #softassertion #hardassertion
Here is the sample TestNG class for your reference-
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
public class SoftAndHardAssertions {
@Test(priority=1)
public void softAssertion() {
SoftAssert softassert = new SoftAssert();
softassert.assertEquals(false, true);
System.out.println("Soft assertion"); // This statment will be executed
softassert.assertAll();
}
@Test(priority=2)
public void hardAssertion() {
Assert.assertEquals(false, true);
System.out.println("Hard assertion"); //This statment will not be executed
}
}
Following points are covered in this video-
What are the different Assertions in TestNG?
How to Use Soft Asserts in TestNG
How to Use Hard Asserts in TestNG
Difference between Soft and hard assert in TestNG.
Keep learning and thanks for watching 👍🙏
Watch video TestNG Assertions | Soft assertion and Hard assertion in Selenium TestNG online without registration, duration hours minute second in high quality. This video was added by user SDET Adda For QA Automation 15 November 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,658 once and liked it 20 people.