我们可以借助@BeforeMethod和@AfterMethod批注为TestNG中的每个测试运行前提方法和后置条件方法。
@BeforeMethod
public void prerequisite(){
System.out.println("Run before every tests");
}
@AfterMethod
public void postcondition(){
System.out.println("Run after every tests ");
}
@Test
public void loanPay(){
System.out.println("Loan pay is successful");
}
在Java类文件中,prerequisite()
将执行带有@BeforeMethod的方法,这被称为每种测试方法的前提。然后loanPay()
将被执行,最后postcondition()
带有@AfterMethod的方法将运行。