Parameterization Using @DataProvider:


  • Using the @DataProvider, we can create data driven framework in which the data is passed through the respective test method and several repetitions of the test run for the various test data values passed from the @DataProvider method.
  • An annotated method with @DataProvider annotation returns a 2D array or object.
  • The @DataProvider is another annotation that supports data-driven testing.
  • Using @Dataprovider annotation of TestNG method is also available in the same class.
  • Using @DataProvider annotation, the same test method can be run multiple times with different data sets.
  • Using the @DataProvider object, the database is read from excel or property files and so on.
  • DataProvider helps in sending many set data to a test method. But here we need to make sure the array given by the DataProvider must match the test method parameter.


There are two types of parameterization in TestNG:

  1. Using Parameters annotation and TestNG XML file.
  2. Using @DataProvider annotation.


Syntax Of @DataProvider:


name: The name of this data provider If this is not supplied then the name of this data provider will be automatically set to the name of the method.


Example Of Parameterization using @DataProvider:

  • org.testng.annotations.DataProvider; package.
  • Using @DataProvider annotation provide name of dataProvider.
  • Using Object[][] return strings with values.





  • With the help of this annotation, you can allow single and also multiple parameter values for test methods.
  • We need to declare a method that gives the data set as a two-dimensional object array Object[][].
  • The first array shows the data set whereas the second array has parameter values.

TestNG Parameterization Using DataProviders and How to use TestNG Parameters & Data Provider for Data Driven Testing