Assertions and Reporting in TestNG

In the previous post, we have learnt how to skip test case and create dependency between test cases. In this post, we will learn about assertions and Reporting in TestNG.

All test cases must have some verification points or check points. Test case pass or fail result will be dependent on these verification points. In selenium scripts, we use assertions for validating these verification points. It can be inserted any where in the scripts depending on test requirements.

In Selenium , we verify very frequently that element is present on the webpage or not. Because if element is not present then test cases should be failed else perform action on the element. This verification can also be done by assertions. Assertions are very powerful and commonly used statements to make the scripts more responsive.

Let’s understand how to use assertions.

1) Assert.assertTrue() & Assert.assertFalse() : AssertTrue will make the test case passed if it finds the expected condition. As an example, we open Gmail application where we are verifying that username is displayed or not. If it displayed, assertTrue will verify the presence of element and continues execution. But if it does not find the element , it will fail the test case and log the corresponding error message.

In the below example, We are intentionally providing the wrong xpath of Username. So, assertion will fail when it does not find the element.

Output: Expected result is failed. So, Assertion will take care of that.

AssetTrue in TestNG


Note: Assert.assertFalse() works opposite of Assert.assertTrue(). It means that if you want your test to continue only if when some certain element is not present on the page. You will use Assert false, so it will fail the test in case of the element present on the page.

2. Assert.assertEquals(): It will verify if expected condition matches with actual condition. If matches, then keep continuing execution. If fails, will stop the execution and remaining statements will not be executed.

Asserequals in TestNG

Reporting in TestNG:

TestNG provides a default reporting as a HTML file. Let’s run the below code and check the reporting.


Reporting testNG

How to check the testNG reporting?

Right click on the project and click Refresh.

Refresh the project


After refreshing project, you will observe a new folder named as ‘test-output’.



Expand the folder ‘test-output’. You will see one file named as ‘index.html’. Right click on the file and copy its path and open this file in a browser.

Index html reporting

Once you will open it in browser, you will see the HTML reporting with all the failed and passed result.

 Testng reporting


This is box title
Have any question or suggestion for us?Please feel free to post in Q&A Forum
Skip test case and create dependency in TestNG
Parameters in TestNG
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...