这个@Factory注释是如何工作的,当我们需要使用@Factory 时
public class Factory1
{
@Factory
public Object[] testMy()
{
return new Object[]{new Login1()};
}
}
请告诉我以下代码的作用,
return new Object[]{new Login1()}
有时我们可能需要使用不同的数据值运行一组测试。为了实现这一点,我们可以在testngXML的套件中定义一组单独的测试,并测试所需的场景。这种方法的问题在于,如果您获得了一组额外的数据,则需要重新定义测试。@Factory
允许在运行时根据特定的数据集或条件创建测试。
让我们以为例
@Factory
public Object[] testMy()
{
return new Object[]{new Login1()};
}
public class login{
public login(){
syso('Login constructor called');
}
output :
Login constructor called
You can also pass arguments and call the constructor multiple times
@Factory
public Object[] testMy()
{
return new Object[]{new Login1(1),new Login1(2)};
}
public class login{
public login(int num){
syso('The number is '+num);
}
output:
The number is 1
The number is 2
希望这对你有帮助。。如果您有任何疑问,请回复