且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

TestNG基本注释二:基本注释解释

更新时间:2022-10-06 21:31:21

TestNG基本注释一中,我们给出来一个用eclipse IDE生成的TestNG测试类:
package test.java.com.testng.test;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.AfterSuite;
public class LoginTest {
@Test(dataProvider = "dp")
public void f(Integer n, String s) {
}
@BeforeMethod
public void beforeMethod() {
}
@AfterMethod
public void afterMethod() {
}
@DataProvider
public Object[][] dp() {
return new Object[][] {
new Object[] { 1, "a" },
new Object[] { 2, "b" },
};
}
@BeforeClass
public void beforeClass() {
}
@AfterClass
public void afterClass() {
}
@BeforeTest
public void beforeTest() {
}
@AfterTest
public void afterTest() {
}
@BeforeSuite
public void beforeSuite() {
}
@AfterSuite
public void afterSuite() {
}
}
上面代码中的具体解释如下:
@BeforeSuite - 针对测试套件,在当前的测试套件运行前执行的方法
@AfterSuite -  针对测试套件,在当前的测试套件运行后执行的方法
@BeforeTest - 针对测试套件, 在任何属于这个类的并且用<test>标签标记的测试方法运行前运行
@AfterTest - 针对测试套件, 在任何属于这个类的并且用<test>标签标记的测试方法运行后运行
@BeforeGroups: 在属于这个组的第一个测试方法运行前运行
@AfterGroups: 在属于这个组的最后一个测试方法被调用后运行
@BeforeClass - 在当前已经被调用的类的第一个测试方法运行前运行
@AfterClass - 在当前类的所有测试方法运行完成后运行
@BeforeMethod - 在每个测试方法前运行
@AfterMethod - 在每个测试方法后运行


最新内容请见作者的GitHub页:http://qaseven.github.io/