Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

TestNG Tutorials 50: DataProvider in TestNG – Understand Basics of DataProvider & How It Works

Posted on 03/21/2025 By admin

Hello Folks,

In last post, we have seen Why do we need to use DataProvider in TestNG. Now we will see a serie of posts on DataProvider.

What is DataProvider?

  • DataProvider is an annotation to mark a method as data provider which provides data as an array of array of Objects which can be used for test or configuration method of a testng class to run on.
  • You need to use it as a normal annotation with any name (Optional). For E.g. @DataProvider(name=”IProvideData”) on top of method signature.
  • A DataProvider method can have a name so that it can be used to supply data to test methods by just mentioning its name.
  • If you do not provide name to a DataProvider method, you can call it with method name on which it was used.
  • A DataProvider annotated method returns an array of array of objects. Remember it can be any dimensional. I see people say that it should be 2D array. It is not like that.
  • Number of values passed by a DataProvider method should be equal to number of attributes of test method on which DataProvider method is used. If DataProvider methods provided three attributes, test method must accept three attributes and vise versa.
  • If attributes counts are not matching at both sides, you will get “org.testng.internal.reflect.MethodMatcherException: Data provider mismatch” exception.
  • The factor which differentiates passing data from a DataProvider method and passing data from testng.xml is that you can pass multiple set of data using DataProvider, on which test method will be run for each set of data.
  • We can execute a test method for multiple set of data using DataProvider which is not possible though Parameters annotation where we pass values from testng.xml.
  • If you are using DataProvider, you do not require testng xml to run it as we need to do in case of Parameters annotation.

Let’s see some examples here which will help you in understanding basic of DataProvider.

Scenario 1: A data provider method which provides N set of single data:

[java]
package DataProvider;

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

public class DataProviderBasics1 {

// You must need to mention data provider method name in Test method @Test(dataProvider=”DataContainer”) public void methodWithSingleAttribute(String a) {

System.out.println(a);

Uncategorized

Post navigation

Previous Post: PROTRACTOR TUTORIAL 2– Identify Angular and Non-angular Application
Next Post: #2. What is the difference between ArrayList and LinkedList In Java?

Related Posts

July 3, 2018 – Make Selenium Easy Uncategorized
October 22, 2017 – Make Selenium Easy Uncategorized
Environment Variables in Postman Uncategorized
mahajan Uncategorized
Make Selenium Easy – Page 27 Uncategorized
angular-icon-1-logo-png-transparent – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark