TestNG Tutorials

TestNG - Gradle example

Gradle is an open-source build automation tool that is designed to be flexible enough to build almost any type of software. Gradle runs on the JVM and you must have a Java Development Kit (JDK) installed to use it. You can find more information on Gradle

You can install the Gradle build tool on Linux, macOS, or Windows.

Allure report example using testng and maven

Allure is an open-source framework designed to create interactive and comprehensive test report by Yandex QA Team

Each time when we run automation tests, we will have test results to view details about no. of tests passed, failed and failure details etc. And few reports also include test failure screenshots. We have discussed selenium examples on Extent report and testng custom report with screenshots.

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, but it records the failure. The test execution will continue with the next step after the assert statement. Calling assertAll() will cause an exception to be thrown if at least one assertion failed.

IMethodInterceptor examples to reorder list of test methods

IMethodInterceptor is used to alter/modify the list of test methods to be executed by TestNG.

When we implement IMethodInterceptor interface which has just one method to implement 'intercept(java.util.List methods, ITestContext context)', using this method we can reorder the list of test methods and return List of IMethodInstance which TestNG runs. TestNG will now run these test methods in the same order which is found in the returned list.

Execute Testng.xml using batch file

In previous tutorial we have seen executing testng.xml tests from command line. Now here we will look into executing testng.xml using batch file (.bat) file. A batch file (.bat) is used in DOS and Windows, which is an unformatted text file that consists of a series of commands to be executed by the command line interpreter.

Let us jump into simple example by taking two classes each has three or more @Test methods.

Customize TestNG html Report

Please visit for the updated article customized emailable report along with screenshots which works perfect for newer versions of testNG and tested with testng latest version 6.14.3

When ever we execute tests with TestNG, it will generate a default html report with basic information.

Optional annotation in TestNG

As we know, we can pass parameter values to the test methods during run time from testng xml file by specifying Parameters annotation to test method.

To do this, we need to declare parameters tag in xml file using 'name' and 'value' attribute.Where the name attribute of the tag defines name of the parameter and the value attribute defines the value of the parameter.