java - Why data provider in a different class, it needs to be a static method -


i have dataprovider in different class , accessing different testng class. observed if not using "static" returning throwing error. want know logic behind this. kindly me on this.

sample code:

error code:

@dataprovider public object[][] testsuminput() { return new object[][] { { 5, 5 }, { 10, 10 }, { 20, 20 } }; } 

correct code:

@dataprovider public static object[][] testsuminput() { return new object[][] { { 5, 5 }, { 10, 10 }, { 20, 20 } }; } 

creating data provider:

@dataprovider(name="dpprojectdetails")     public static object[][] supplyprojectdetails(){         int noofrows=commonmethods.getrowcount(commonmethods.xlpath_project_details, commonmethods.sheet_project_details);         int noofcell=commonmethods.getcellcount(commonmethods.xlpath_project_details, commonmethods.sheet_project_details);         object[][] projectdetails=new object[noofrows][noofcell];           for(int row=1;row<=noofrows;row++){             for(int cell=0;cell<noofcell;cell++){                 projectdetails[row-1][cell]=commonmethods.getexceldata(commonmethods.xlpath_project_details, commonmethods.sheet_project_details, row, cell);             }         }          return projectdetails;     }  } 

-->accessing it:

@test(dataprovider="dpcustomerdata", dataproviderclass=tdcreatecustomer.class)     public void createnewcustomer(string customername,string custdescription){         tdcreatecustomer tdcreatecustomer=new tdcreatecustomer();         pocreatecustomer pocreatecustomer=new pocreatecustomer();          tdcreatecustomer.setcustomername(customername);         tdcreatecustomer.setdescription(custdescription);          pocreatecustomer.createnewcustomer(tdcreatecustomer);     } 

it means trying access incorrectly. should never try access directly, rather should make variables non-static , private , should access them indirectly via non-static public methods , calling methods on instance of class.

in other words of problem in code you've not shown -- code try "access" data.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -