TestNG Introduction

In this post ,we will be studying about TestNG, a widely used testing framework supporting all levels of testing from Unit to automated functional tests. We will see its usage in selenium tests and also have a look at its advantages.

What is TestNG?

TestNG is a JUnit inspired testing framework providing several features like data driven testing, parameterization support, different utility annotations and test case grouping that aid in creating robust and powerful testing projects.

public void sampleTest() {   
   //Any test logic
   System.out.println("Hi! ArtOfTesting here!");   

Features of TestNG

  1. Different Types of Assertions – TestNG has an Assert class that provides multiple methods supporting different types of assertions like checking equality of expected and actual result, asserting a condition as True or False, asserting if a value is Null etc.
  2. Run tests in Parallel – Using its testNG.xml file we can run test cases in parallel, thus reducing the overall test execution time. The parallel execution can be done in multiple levels – method level, class level, suite level. For details check Running Selenium Tests in Parallel using TestNG.
  3. Make tests dependent on one another – Using its ‘dependsOnMethods’ and ‘dependsOnGroups’ attribute with @Test annotation, we can make test dependent on other tests.
  4. Prioritizing tests – In TestNG we can assign a numerical priority value to the Tests with 0 being the default value.
  5. Grouping of tests – TestNG supports logical grouping of test cases. Thus, providing ability to run the test groups in parallel, perforimg certain operations before or after the execution of the tests belonging to a group.
  6. Data Driven Testing – Using @DataProvider we can create data driven tests in which the test data is passed to the test method through its data provider.
  7. Reporting – After test execution an HTML report gets created providing tabular reporting of test results. The reporting format is also configurable by implementing TestNG listeners.
  8. Parameterization – TestNG provides inherent support for parameterization using its @Parameters annotation. The value of the parameter defined using @Parameters annotation is passed to the test logic from the testng.xml file.

We will be exploring the different features of TestNG along with examples in the coming posts.

Leave a Comment