TestNG


TestNG is a testing framework for the Java programming language created by Cédric Beust and inspired by JUnit and NUnit. The design goal of TestNG is to cover a wider range of test categories: unit, functional, end-to-end, integration, etc., with more powerful and easy-to-use functionalities.

Features

TestNG's main features include:
  1. Annotation support.
  2. Support for data-driven/parameterized testing.
  3. Support for multiple instances of the same test class
  4. Flexible execution model. TestNG can be run either by Ant via build.xml, or by an IDE plugin with visual results. There isn't a TestSuite class, while test suites, groups and tests selected to run are defined and configured by XML files.
  5. Concurrent testing: run tests in arbitrarily big thread pools with various policies available, and test whether the code is multithread safe.
  6. Embeds BeanShell for further flexibility.
  7. Default JDK functions for runtime and logging.
  8. Dependent methods for application server testing.
  9. Distributed testing: allows distribution of tests on slave machines.

Data provider

A data provider in TestNG is a method in a test class, which provides an array of varied actual values to dependent test methods.
Example:

//This method will provide data to any test method that declares that its Data Provider is named "provider1".
@DataProvider
public Object createData1
// This test method declares that its data should be supplied by the Data Provider named "provider1".
@Test
public void verifyData1
// A data provider which returns an iterator of parameter arrays.
@DataProvider
public Iterator createData
// A data provider with an argument of the type java.lang.reflect.Method.
// It is particularly useful when several test methods use the same
// provider and you want it to return different values depending on
// which test method it is serving.
@DataProvider
public Object createData

The returned type of a data provider can be one of the following two types: