Java Scrap Book  

Java Scrap Book > TestNG > Data Provider Annotation

Data Provider Annotation

@DataProvider annotation helps a method become data source for test methods.
A method which have @DataProvider annotation must return an Object[][] where each object[] is parameter list for test method.

e.g @DataProvider
public Object[][] testDataProvider()

Data provider name should be pass as argument in @Test method , which will execute test on Data provider data set.
e.g @Test(dataProvider = "testDataProvider")

package com.javascrapbook.testng;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class DataProviderTest {

public Object[][] testDataProvider() {
return new Object[][] { { "Hello" }, { "world" } };

@Test(dataProvider = "testDataProvider")
public void getDataValue(String data) {


PASSED: getDataValue("Hello")
PASSED: getDataValue("world")

Copyright © 2013-2019 is a computer science content service should not be treated as the publisher or speaker of any information provided by another Computer Science content provider.

Contact email: