TestNG Framework

TestNG Framework


TestNG is an open-source test automation framework for Java. The NG in TestNG stands for ‘Next Generation’, created by Cedric Beust, it is used more frequently by developers and testers in test case creation, owing to its ease of using multiple annotations, grouping, dependence, prioritization, and parametrization features. Many plugins are integrated with TestNG.

Advantages of TestNG

  1. TestNG provides Parallel execution of test Method.
  2. It allows to define dependency of one test method over other method.
  3. It has support for parameterizing test cases using @Parameter annotation.
  4. It has different assertions that helps in checking the expected and actual results.
  5. It allows data driven driven testing using @Data provides annotation.
  6. It can be use Test Method annotation(@test) Instead of Main method for Execution.
  7. Can we call Non static method without creating object but, we can call through the TestNG.

Installation of TestNG

Step 1. Launch Eclipse and click on the help menu then select ‘Eclipse Marketplace’

Launch Eclipse

Step 2: A new window for ‘Eclipse Marketplace’ will open, enter ‘TestNG’ in the find box on the top left and click on the go button and then click on install.

Eclipse Marketplace

Step 3: After that click on libraries and select ‘Add Library’, then select TestNG and click on finish button.

TestNG and click on finish button
  • Generate TestNG.XML file

Click on TestNG and then select convert to TestNG to generate the ‘TestNG.XML’ file

Generate TestNG.XML file

Execution of TestNG.XML file

  • Click on TestNG.xml file and click on run as TestNG suite.

Importance of TestNG.XML file

  1. TestNG.XML file to configure the complete test suite in a single file
  2. It allows Include or exclude the execution of test methods and test groups
  3. Allows Pass parameters to the testcases
  4. Allows add group dependencies
  5. Allows to configure parallel execution of test cases

TestNG Class

It is a java class which consist of Test method annotation(@Test)

Test Method– Any method which is developed by using Test annotation is called as Test method, for ex.

Package Demo;

import org. testing. Reporter;

public class Test A



public void test1()


Reporter.Log(“1”, true);



Important Annotations of TestNG

  • @ Before Suite
  • @ Before Test
  • @ Before Class
  • @Before Method – Used to perform opening the Application
  • @Test- Used to perform action on the browser
  • @ After Method- Used to perform to close the Application
  • @After Class
  • @After Test
  • @ After Suite
  • @ Find By
  • @ Parameter
  • @Data provider

How to skip the testcases

  1. Invocation count=0
  2. @Ignore
  3. @Test (Enabled=false)
  4. depends on Method
  5. depends on group
  6. Commenting the Test Method (/*——-*/)
  7. Throw new skip exception ();

Example: –

@Test (Priority=2, invocation count=3, enabled=false)

public void test 1 ()


system.out.printlin(“test 1”);



public void test 1 ()


system.out.printlin(“test 2”);


Output: test2

Parameterized test

This can be done in two ways

  1. With testing.xml(@Parameters)
  2. With Data providers (@ Data providers)
  • Create a java test class, say, TestParameterized.java.
  • Add test method parameterTest() to your test class.
  • Add the annotation @Parameters(“name”) to this method. The parameter would be passed a value from testng.xml

Create a java class file named TestParameterized.java 

Example: –

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;

public class ParameterizedTest1




               public void Test parameter (String Name)


                               System.out.println(“Parameterized value is: ” + Name);



Create testng.xml

<?xml version = “1.0” encoding = “UTF-8”?>

<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd” >

<suite name = “Suite1”>

<test name = “test1”>

<parameter name = “Name” value=”Abc”/>


<class name = “TestParameterized” />




Data providers

  • It executes Same set of testcases with different inputs and to read data from the excel file
  • Return type of data providers is 2dimensional arrary

Example: –

@Data provider

public string [][] dp() throws Encrypted document exception, IO Exception, Invalid Format exception


FileInputStreamfis= new FileInputStream(“Path of excel sheet”);

Workbook wb= wb.getsheet(“sheet 1”);

Row firstRow= s.getRow(0);

int row count=s.getpgysical number of Row();

int col count= first Row.getLastcell Num ();

for (int i=1; i<rwo count; i++)


for (int j=0; j<colcount; j++)


arr[i][j]=s.getRow(i).s.getce;;(j).to string();



@Test (data provider=” dp”)

public void test (String s1, String s2)






How to perform failed testcases automatically

Failed testcases can run through by using I Retry Analyzer

Example: –

Class name retry.java

public class retry implements IRetry Analyzer


Int count=0;

Int max_count=3;

public Boolean retry(ITestResult result)


if (count<max count)



return true;


return false;



Leave a Reply

SOAIS - Worksoft Newsletter

To view on your browser, click here
Facebook Twitter LinkedIn
Dear Default Value,

Welcome to SOAIS Newsletter of September 2021!

Continuous Testing with Remote Execution
The speed of innovation continues to increase, driving rapid and relentless change for today’s ever-evolving IT landscapes, creating greater risk as IT and business teams scramble to ensure timely delivery. How can your organization keep pace? Test more, worry less. With Worksoft’s Connective Automation Platform, you can easily build and maintain automated tests, accelerating testing time without losing scope or volume. You can schedule and execute remote, continuous tests to intercept defects sooner and prioritize remediation - without sacrificing your nights and weekends. Explore how continuous test automation and remote execution can empower your organization.

Click here to connect with us to get more information on our services.

Skip Costly Rework with Dynamic Change Resiliency​

Change resiliency is imperative in ever-evolving IT environments. Our patented object action framework streamlines change management by assigning object definitions to your shared assets. The same object may be used in a thousand automation steps, but it can be easily updated by making one simple change to the model definition. The change automatically propagates to every single instance where that object may have been used without a single line of code or manual human involvement. For more change readiness you can also engage our Impact Analysis for SAP to predict how changes in SAP transports will affect your business processes. 

Please click here to watch the video to get a gist.

SOAIS Blog – Nuts and bolts of Certify Database Maintenance​

One of the key thing, which is often missed by the organizations, who have invested in using Worksoft Certify for automating their Business Process Validation initiatives, is implementing a Database Maintenance Plan. While the business and the test automation consultants get excited about the shiny new thing that they have got and start building the regression suite; planning and executing a database maintenance plan for most of the customers gets pushed down the priority list. However, since all the test assets in Certify are stored in a Database, a robust database maintenance plan is very important to maintain smooth operation of Certify with acceptable performance criteria. The customers usually start facing issues once they have built significant number of Certify processes which they have started executing on regular basis. Such executions add a lot of data to the tables storing results data and increase the overall size of the Certify database.

Please click here to read the complete blog.

Worksoft Blog – Process Intelligence: A Multi-Dimensional Approach

The ability to extract process knowledge has become easier through the years. Technology has evolved to the point where we can deploy capabilities that connect at multiple levels to extract different types of process insight. In the past, organizations were forced to spend enormous energy extracting data manually from different applications and databases. Then, they would have to use things like spreadsheets to transform the data and convert it into meaningful information. 

Please click here and read the complete blog.
Unit 9, Level 5, Navigator, ITPL,
Bangalore - 560 066.
Phone: +91 80 40071234
Suite 101, 1979, N Mill St,
Naperville, IL 60563
Phone 1-800-262-2427
Please click here to Unsubscribe / Unsubscribe Preferences

Leave us your info