当我们需要使用 @Factory 时,这个 @Factory 注释是如何工作的
public class Factory1
{
@Factory
public Object[] testMy()
{
return new Object[]{new Login1()};
}
}
请告诉我以下代码的作用,
return new Object[]{new Login1()}
当我们需要使用 @Factory 时,这个 @Factory 注释是如何工作的
public class Factory1
{
@Factory
public Object[] testMy()
{
return new Object[]{new Login1()};
}
}
请告诉我以下代码的作用,
return new Object[]{new Login1()}
有时我们可能需要运行一组具有不同数据值的测试。为了实现这一点,我们可以在 testng XML 的套件中定义一组单独的测试并测试所需的场景。这种方法的问题在于,如果您获得一组额外的数据,您将需要重新定义测试。@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
希望这对您有所帮助..如果您有任何疑问,请回复