Last updated on September 7th, 2018 at 12:25 pm
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:
- 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:
Now question comes here that:
- What factors make us to use DataProvider over testng.xml?
- 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:
- 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.
- 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.
- 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.
- DataProvider also provides you flexibility to run a test method for specific set of data using indices. We will see this in upcoming posts.
- DataProvider also provides you to run a test method parallely with different set of data. We will see this in upcoming posts.
- 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.
Author: Amod Mahajan
My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning