TestNG is an Free (Open-Source) unit test automation framework for Java.

TestNG is developed on the same manner as JUnit and NUnit unit frameworks, but introduced some new advanced features and functionalities provided by TestNG, because of that TestNG is more powerfull than Junit and Nuint frameworks.

The TestNG in NG stands for “Next Generation“.

TestNG is a unit testing framework inspired by JUnit and NUnit with more functionality added to make execution easy, more efficient, and more powerful.

It is a Free (Open-Source) automated testing framework.

The TestNG in NG stands for “Next Generation“.

The TestNG Latest Version: 7.4.0(Java Project) / 7.8.0(Maven)

It is similar to JUnit and Nuint but it is more powerful than JUnit and NUnit.

TestNG eliminates most of the limitations of the older framework and gives the developer and tester the ability to write more flexible and powerful tests code with help of easy annotations, grouping, sequencing & parameterizing.

The Main Advantages of TestNG are and provides many features for running the test case as mentioned below:

  • Using TestNG provides inbuilt generating reports and the ability to produce HTML Reports of execution (Default test.html, emailable-report.html, and index.html) and which the webdriver can’t do on its own.
  • Annotations make code efficient and easy to manage our test scripts.
  • We can easily get to know how many test cases passed, failed, and skipped.
  • By default test cases are executing alphabetically order.
  • Test cases can be Prioritized. We can provide priority feature for the test scripts, like which test case needs to execute first and which next.
  • We can disable or exclude the test cases by using the “enable” attribute to the @Test annotation and assigning a “False” value.
  • TestNG provide the timeOut feature to the execution of a test method if that method takes time beyond the timeOut duration.
  • We can run a group of test cases using a grouping feature.
  • TestNG allows you to specify dependencies in our test case methods.
  • Run the test scripts parallel testing is possible. Since it provides Parallel testing it is to test scripts on multiple browsers simultaneously.
  • Data Parameterization is possible
  • We can run multiple scripts ( Suite ) at a time
  • We can execute failed test cases separately.
  • It supports flexible runtime configurations
  • It supports multi-threaded testing
  • We have the option to set pre and post-conditions like what needs to happen before and after the execution of scripts.
  • TestNG provides listeners to run failed test cases again as many times as they want in a single run
  • It is easy to provide data through Excel or CSV files using @DataProvider annotation and Use the parameters and Data-provider for handling excel data.
  • Using TestNG Annotations, @BeforeSuite,@AfterSuite, @BeforeTest, @AfterTest, @BeforeClass, @AfterClass, @BeforeMethod, @AfterMethod annotations there is no need for methods and that need to take care of before or after running any test scripts
  • There is no more need for a static main method in our tests.
  • It is designed to cover all categories of testing types – Unit, Integration, Functional, Regression, Retesting, End-to-end, UI, API, Mobile, etc.
  • Uncaught exceptions are automatically handled by TestNG without terminating the test prematurely and These exceptions are reported as failed steps in the report.
  • TestNG allows users to do test configuration through XML files and allows them to include (or exclude) respective packages, classes, and methods in their test suite.

Annotations in TestNG:

1) @Test

2) @BeforeSuite

3) @AfterSuite

4) @BeforeClass

5) @AfterClass

6) @BeforeTest

7) @AfterTest

8) @BeforeGroups

9) @AfterGroups

10)@BeforeMethod

11)@AfterMethod

12)@DataProvider

13)@Factory

14)@Listeners

15)@Parameters

@BeforeSuite: The method with this annotation will run before all tests in the test suite

@AfterSuite: The method with this annotation will run after all tests in the test suite

@BeforeTest: The method with this annotation will run before each and every test method with tag in xml file

@AfterTest: The method with this annotation will run after each and every test method with tag in xml file

@BeforeClass: The method with this annotation will run before first test method in the current class

@AfterClass: The method with this annotation will run after last test method in the current class

@BeforeMethod: The method with this annotation will run before each test method

@AfterMethod: The method with this annotation will run after each test method

@Test: The annotated method is a part of a test case

These are the reason nowadays TestNG has become more important than Selenium itself.