Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

TestNG Tutorials 49: Need of DataProvider Method in TestNG

Posted on 03/21/2025 By admin

Hello Folks,

TestNG provides a beautiful functionality to parameterized our configuration and test methods so that we can execute the same test script with different set of data. To make a method (Configuration and Test) parameterized , we use “Parameters” annotation. If we make a method parameterized, we must need to pass parameters values from somewhere. TestNG provides below ways to do the same:

  1. Parameters from testng.xmlParameters from DataProvider

We have seen a lot of examples on “Parameters from testng.xml” already. You can go through them here:

TestNG Tutorials 42: Parameters In TestNG or Parameterization of Methods in a TestNG Class

TestNG Tutorials 43: Difference Between “Parameters” and “parameter” in TestNG

TestNG Tutorials 44: Constructor with @Parameter Annotation

TestNG Tutorials 45: Passing Parameters at Test Method Level in TestNG

TestNG Tutorials 46: Overriding Parameters in TestNG

TestNG Tutorials 47: Marking a Parameter as Optional in TestNG

Now question comes here that:

  1. What factors make us to use DataProvider over testng.xml?
  2. When we should go for testng.xml or DataProvider or both?

Both they ways of providing parameters values in TestNG have their own advantages. We will compare them here:

  1. Parameters is a great functionality as it eliminate the need of hard coded data within script. Using testng.xml we can provide data to parameters. But do not you think that testng.xml is related/part to script directly or indirectly? Its ok that data is separated from scripts but can you give this testng.xml to a BA or Manual Testers to update data? They might feel difficult to update an xml.  But if you pass data from an Excel or properties file or Database, it will be easier to update data for anyone as per their required data to run tests. Manual tester or BA can easily update data and execute scripts. Since you can not read data from external sources like Excel, DB etc through parameter tag in testng.xml, we must need to use DataProvider.
  2. If we need to run a test with multiple set of data, we need to use DataProvider. Passing a set of data using testng.xml is not possible. It is also a way of achieving data driven testing with TestNG. But remember DataProvider is not a good way of achieving data driven testing.
  3. If values to parameters are being decided during run time from previous tests, you need to use DataProvider only as you can not modify testng.xml at run time.
  4. DataProvider also provides you flexibility to run a test method for specific set of data using indices. We will see this in upcoming posts.
  5. DataProvider also provides you to run a test method parallely with different set of data. We will see this in upcoming posts.
  6. You can pass value of any type including user defined class type as well which is not possible in Parameters.

I think now you can understand actual usage of DataProvider. We will see a lot about DataProvider in upcoming posts.

More about TestNG in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below. If you like my posts, please like, comment, share and subscribe. #ThanksForReading

#HappySelenium

Uncategorized

Post navigation

Previous Post: Create A List Of Map From Excel Data In Java – Selenium – API Automation
Next Post: Frequently Asked Java Program 24: Java Program to Capitalize First Character of Each Word in a String Sentence

Related Posts

May 2018 – Make Selenium Easy Uncategorized
REST Assured Tutorial 48 – How To Pass Headers In Rest Assured Requests Uncategorized
Setup of selenium project and How to open a chrome browser – Make Selenium Easy Uncategorized
November 16, 2018 – Make Selenium Easy Uncategorized
May 25, 2018 – Make Selenium Easy Uncategorized
REST Assured Tutorial 34 – Serialization – Java Object To JSON Object Using Gson API 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