Java – TestNG – @ aftermethod priority

Can the @ aftermethod method method be called in a specific order?

public class PriorityTest {

@BeforeClass(alwaysRun = true)
public void setUp() throws Exception {
    System.out.println("BeforeClass PriorityTest.java");
}

@Test
public void defaultPriority(){
    System.out.println("default");
}
@Test (priority = 3)
public void t1(){
    System.out.println("t1");
}
@Test (priority = 2)
public void t2(){
    System.out.println("t2");
}
@Test (priority = 1)
public void t3(){
    System.out.println("t3");
}
@Test (priority = -1)
public void t_1(){
    System.out.println("t -1");
}

@AfterMethod
public void after2(){
    System.out.println("after2");
}
@AfterMethod
public void after1(){
    System.out.println("after1");
}

}

@The priority of test is perfect I want to do the same for @ aftermethod, but when I write @ aftermethod (priority = 1), it is a compilation error When I don't have priority, I always arrange it alphabetically (only the method name is important) This is the output:

BeforeClass PriorityTest. Java T - 1 after1 after2 default after1 after2 T3 after1 after2 T2 after1 after2 T1 after1 after2

Is it possible to call the method in a specific order (such as special parameters or comments)?

PS. I know I can write an aftermethod and call the methods in a specific order, but I think of many aftermethod comments

Solution

@Aftermethod does not support priority parameters But it depends on useonmethods and dependsongroups, which can be used instead

dependsOnMethods

dependsOnGroups

In your case, you can use dependsonmethods

@AfterMethod
public void after2(){
    System.out.println("after2");
}
@AfterMethod(dependsOnMethods = "after2")
public void after1(){
    System.out.println("after1");
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>