Sunday, July 7, 2019

Soft Assertion Vs Hard Assertion in TestNG

In test automation, when we want to validate the results or some conditions we use Assertion class. If the condition fails, subsequent steps will be aborted and test will be marked as failed. This type of assertion is called Hard Assertion.

The disadvantage of Hard Assertion is when we have more assertions in a test and if the assertion at the beginning fails all the subsequent assertions will be not executed/validated. And if we create one test case for each assertion that is not good practice.

Hard Assertion Example: In the below example, we have 3 assertions verifying employee name, employee id and employee email.

When we execute the code, the first assertion is failed and next two assertions are not executed.

Here comes Soft Assertions which helps to validate all the assertions even if one among them fails. Soft Assertion is a feature provided by TestNG. It is same like Hard Assertion but it doesn't abort the subsequent steps when a condition fails, it will continue executing the subsequent steps also.

Soft Assertion Example: Lets the take above example and use Soft Assertion.

When we execute the code, even though the first assertion fail it will continue to second and third assertions. And we used  assertAll() method of soft assertion  to know which assertions passed and which assertions failed.

Hope you understood the difference between hard and soft assertions. Please comment if any queries.

Thanks for reading. #HappyLearning #HappyTesting


  1. We offer comprehensive solutions to present compelling essays written by very professional writers who bring more chance to expand our array of best essay writing service. We grasp the burden of students regarding unlike subjects and the force of different gung ho exams which takes a toll on their everyday routine. best essay writing service

  2. Good Explanation . Pretty easy to understand and crisp

  3. Very Well explained Sir. Thank You so much :)

  4. appriciate, got clear picture of both Assertions. keep doing.


Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...