是否可以使用不同的@before方法多次运行@Test testNG注释?

是否可以使用不同的@before方法多次运行@Test testNG注释?,testng,Testng,我有3个方法(“setup1”、“setup2”、“setup3”),我在每个方法上都使用@BeforeMethod注释。每个方法都有不同的功能,我想运行方法Test1()3次,每次都使用不同的@BeforeMethod方法(例如:run1:setup1()>>Test1(),run2:setup2()>>Test1(),run3:setup3()>>Test1()。可能吗 这是我的代码: @BeforeMethod public void setup1() { //do somethi

我有3个方法(“setup1”、“setup2”、“setup3”),我在每个方法上都使用@BeforeMethod注释。每个方法都有不同的功能,我想运行方法Test1()3次,每次都使用不同的@BeforeMethod方法(例如:run1:setup1()>>Test1(),run2:setup2()>>Test1(),run3:setup3()>>Test1()。可能吗

这是我的代码:

@BeforeMethod
public void setup1() {
    //do something
}

@BeforeMethod 
public void setup2() {
    //do something else
}

@BeforeMethod 
public void setup3() {
    //do something else
}    

@Test
public void Test1() {
    //do something    
}
我尝试在@Test内使用dependsOnMethods{}:

@Test(dependsOnMethods = {"setup1","setup2", "setup3"})
    public void Test1(){
    //do something
} 

但是这种方法不起作用,因为它在进入Test1()之前会同时运行所有3个@before方法,我想完成的是运行setup1()>>Test1(),运行setup2()>>Test1(),最后运行setup3()>>Test1()。

您可以创建一个数据提供程序方法,在它里面,您可以创建3个不同的用户,并将其传递给测试方法。因此,将为每个用户调用测试方法

@Test(dataProvider = "users")
public void Test1(User user) {
    //do something with user   
}

@DataProvider
public Object[][] users(){
   User user1 = null; //replace the null with code to create user1
   User user2 = null; //replace the null with code to create user2
   User user3 = null; //replace the null with code to create user3
   return new Object[][]{{user1},{user2},{user3}};
}

我不认为类似的实现可以通过使用BeforeMethod来实现,你能指定BeforeMethod的每个功能吗?或者是否可以在数据提供程序中执行这3种不同的操作,并将结果作为每个测试用例传递给测试方法?每个BeforeMethod将使用不同的用户/通过凭据登录用户,并且测试方法将为每个用户执行相同的操作。感谢您的指导。