Parameterization Using @DataProvider

@Parameters annotation is easy to use but to test with multiple sets of data we need to use Data Provider. To fill thousand’s of web forms using our testing framework we need a different methodology which can give us a very large data set in a single execution flow. This data driven concept is achieved by @DataProvider annotation in TestNG.

  • 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.

Syntax Of @DataProvider

@DataProvider(name = "data-provider")
 
public Object[][] dataProviderMethod() {
 
}

It has only one attribute name. If the name of this data provider is not supplied then the name of this data provider will be automatically set to the name of the method.

Next
TestNG
Home Page

Leave a comment

Design a site like this with WordPress.com
Get started