TestNG factory class with example
@Factory is used to create different instance of Test class and is useful annotation when you run test multiple time.
you can find examples with description for both at : http://testng.org/doc/index.
DataProvider Example:
public class DataProviderDemo {
@DataProvider(name="myDataProvider")
public Object[][] data(){
return new Object[][]{ {"adf",5.0f}, {"dfds",4.0f} };
}
@Test(dataProvider="myDataProvider")
public void method1( String strData ,float floatData){
Reporter.log("String "+strData);
Reporter.log("float "+floatData);
}
}
Factory Example:
public class FactoryDemo {
String strData;
float floatData;
public FactoryDemo(String string, float f){
strData = string;
floatData = f;
}
@Factory
public static Object[] data(){
return new Object[]{ new FactoryDemo("adf",5.0f), new FactoryDemo("dfds",4.0f) };
}
@Test()
public void method1(){
Reporter.log("String "+strData);
Reporter.log("float "+floatData);
}
}
No comments:
Post a Comment