TestNG is a testing framework inspired from JUnit and NUnit, its existing features has make it more powerful. TestNg provide seamless integration with Jira, Jenkins, Cucumber, Maven etc

It has given rich libraries for better test development to Software test developers .

Some of the common features(Referred testng.org) of TestNg are-

1-Annotations-Different annotation which control or structure test properly.
2-Run your tests in arbitrarily big thread pools with various policies available (all methods in their own thread, 3-one thread per test class, etc…).
4-Test that your code is multi thread safe.
5-Flexible test configuration- Parameterisation, annotation etc
6-Support for data-driven testing (with @DataProvider). When data driven tests are required, with the help of data provider, same can be achieved.
7-Support for parameters- Same test can be executed with different input data, commonly sending data from xml file.
8-Powerful execution model (no more TestSuite)- can be integrated with CI tools etc
9-Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, CI tools too etc…).
10-Default JDK functions for runtime and logging (no dependencies).
11-Dependent methods for application server testing.

TestNG is designed to cover all categories of tests: unit, functional, end-to-end,regression and integration, etc

How to install it, in Eclipse-

1- Go to Eclipse MarketPlace, Search TestNG

2- Select the TestNG option, Agree the Terms and Conditions and install it.

Once after TestNg is installed, create a class(without selecting Main checkbox) in your java project.

Find below Widely used annotations in TestNG-

@BeforeSuite- Executes method before start of test suite
@BeforeTest-Executes before test methods of particular class
@Test-Method will be executed as test method
@Test(Priority=n)-Test Method executes in defined priority
@Test(DependsOnMethod={“Method”})-Executed only when dependent method is passed.
@BeforeGroups: The list of groups that this configuration method will run before. This method is runs shortly before the first test method that belongs to any of these groups is invoked.
@AfterGroups: The list of groups that this configuration method will run after. This method runs shortly after the last test method that belongs to any of these groups is invoked.

package Selenium_Example;
import junit.framework.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class TestNG_Example
public void BeforeSuite()
System.out.println("Before Suite-I am in Setup");

public void Setup()
System.out.println("Beforetest-I am in Setup");

public void Test1()
System.out.println("I am in Test1");

public void Test2()
System.out.println("I am in Test2");


@Test(priority=3, dependsOnMethods={"Test2"})
public void Test3()
System.out.println("I am in Test1");

public void PostTestValidation()




Before Suite-I am in Setup
Beforetest-I am in Setup
I am in Test1
I am in Test2

Test3 is not executed because if you see annotation in Test3 method is (DependsonMethod) which is test2 and since I have deliberately failed that method, Test3 is not executed.

Also, Once after execution, test-output folder is generated, which is basically default reporting of TestNG, It has various reports like index.html file which has summary of execution, emailable-report.html and testng-failed.xml(which contains test cases which are failed).

Also Output statements can explain Sequence of method execution-

i-first beforeSuite annotation is executed, then
[email protected],

Major advantages of TestNG over JUnit:

1-Annotations are easier to understand and implement
2-Test cases can be clubbed more easily using group annotation
3-Parallel testing is possible


TestNG is a testing framework that is capable of making Selenium tests user friendly. The main advantages of TestNG over JUnit are the following.

1- Annotations are easier to use and understand.
2- Test cases can be clubbed more easily.
3-TestNG allows us to create parallel tests.
4- TestNG reports generative more interactive output after every test execution which is easy to understand as well as strategically designed to present various aspect of test result like-
i-Runtimes of each method.
ii-The chronological order by which methods were executed
5-TestNG is capable of generating HTML-based reports as well as report customization is also possible.