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.

@Test
public void sampleTest() {   
   //Any test logic
   System.out.println("Hi! QA Earth here!");   
}

Features of TestNG


  • 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.
  • 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.
  • Make tests dependent on one another - Using its 'dependsOnMethods' and 'dependsOnGroups' attribute with @Test annotation, we can make test dependent on other tests.
  • Prioritizing tests - In TestNG we can assign a numerical priority value to the Tests with 0 being the default value.
  • 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.
  • 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.
  • 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.
  • 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.