How to pass class Object through Dataprovider TestNG
A DataProvider in TestNG is a method in a test class, which provides an array of varied actual values to dependent test methods.(WIKI)
Check below how to pass class object to test Method using DataProvider.
Please note in Test method, passed parameter type should be of type of Object that you have added to your object array in dataprovider method.
@DataProvider(name = "dataForTest")
public static Object[][] data()
{
Object[][] data = new Object[1][1];
Dummy dum = new Dummy("DummyName ", 246);
return new Object []{dum};
}
public class testDataProvider {
@Test(dataProviderClass = DataProvider.class,dataProvider = "dataForTest")
public void testMethod(Dummy Dumb) {
System.out.println("Dumb Name" +" " + Dumb.getName() +" " + " Dumb Salary " + Dumb.getSalary());
}
}
Here is my Dumb class
public class Dummy {
private String name;
private int salary;
public Dummy(String name, int salary){
this.name=name;
this.salary=salary;
}
public String getName() {
return name;
}
public int getSalary() {
return salary;
}
}
One must Remember Point about test iterations
Object[][] data = new Object[1][1];
With above data ,your test will run 1 time and will take one parameter
Similarly
Object[][] data = new Object[2][1];
and this one will run 2 times and will take one parameter.
Check below how to pass class object to test Method using DataProvider.
Please note in Test method, passed parameter type should be of type of Object that you have added to your object array in dataprovider method.
@DataProvider(name = "dataForTest")
public static Object[][] data()
{
Object[][] data = new Object[1][1];
Dummy dum = new Dummy("DummyName ", 246);
return new Object []{dum};
}
public class testDataProvider {
@Test(dataProviderClass = DataProvider.class,dataProvider = "dataForTest")
public void testMethod(Dummy Dumb) {
System.out.println("Dumb Name" +" " + Dumb.getName() +" " + " Dumb Salary " + Dumb.getSalary());
}
}
Here is my Dumb class
public class Dummy {
private String name;
private int salary;
public Dummy(String name, int salary){
this.name=name;
this.salary=salary;
}
public String getName() {
return name;
}
public int getSalary() {
return salary;
}
}
One must Remember Point about test iterations
Object[][] data = new Object[1][1];
With above data ,your test will run 1 time and will take one parameter
Similarly
Object[][] data = new Object[2][1];
and this one will run 2 times and will take one parameter.
very nice, thanks for precise solution
ReplyDeleteBig Truck Tow: Heavy Duty towing service san jose
ReplyDeleteWe're rated the most reliable heavy duty towing san jose service & roadside assistance in San Jose!
Call us now! We're ready to help you NOW!
Since 1999, tow truck san jose has provided quality services to clients by providing them
with the professional care they deserve. We are a professional and affordable Commercial
Towing Company. BIG TRUCK TOW provides a variety of services, look below for the list of
services we offer. Get in touch today to learn more about our heavy duty towing
Click here to Find tow truck near me
I think I have never watched such online diaries ever that has absolute things with all nuances which I need. So thoughtfully update this ever for us.
ReplyDelete360DigiTMG big data course malaysia
Plumbing & HVAC Services San Diego
ReplyDeleteAir Star Heating guarantees reliability and quality for all equipment and services.
Air Star Heating is specializing in providing top-quality heating, ventilating, air conditioning, and plumbing services to our customers and clients.
Our company is leading the market right now. By using our seamless and huge array of services. Our customers can now have the privilege of taking benefit from our services very easily and swiftly. To cope up with the desires and needs of our clients we have built an excellent reputation. We are already having a huge list of satisfied customers that seem to be very pleased with our services.
Plumbing & HVAC Services in San Diego. Call now (858) 900-9977 ✓Licensed & Insured ✓Certified Experts ✓Same Day Appointment ✓Original Parts Only ✓Warranty On Every Job.
Visit:- https://airstarheating.com