How To Use DataProviders In TestNG

Image for post
Image for post

Note: The code samples may be displayed improperly because of markdown. I recommend continuing to read the original article on our blog to make sure all the examples are displayed properly.

What is a DataProvider in TestNG?

@DataProvider(name = ”name of the data provider”)
public Object[][] dataProviderfunc(){
Return new Object[][]{
values
}
}

Using DataProvider in TestNG

Image for post
Image for post

Inheriting DataProvider in TestNG

package dataProviders;
import org.testng.annotations.DataProvider;
public class DPClass {
@DataProvider(name = “test-data”)
public static Object[][] dataProvFunc(){
return new Object[][]{
{“Lambda Test”},{“Automation”}
};
}
}
Image for post
Image for post

Passing Multiple Parameter Values in TestNG DataProviders

Image for post
Image for post

DataProvider in TestNG using Excel

Create a Test Data Sheet

Image for post
Image for post
Image for post
Image for post

Conclusion

Author Kritika Murari

Written by

Product Growth at @lambdatesting (www.lambdatest.com)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store