這篇文章介紹的註解包括@BeforeMethod/@AfterMethod、@BeforeClass/@AfterClass、@BeforeSuite/@AfterSuite
直接在BasicAnnotation 類右鍵,運行這個類
import org.testng.annotations.*;
public class BasicAnnotation {
//最基本的註解,用來把方法標記爲測試的一部分
@Test
public void testCase1(){
System.out.println("這是測試用例1");
}
@Test
public void testCase2(){
System.out.println("這是測試用例2");
}
@BeforeMethod
public void beforeMethod(){
System.out.println("執行beforeMethod,這是在測試方法之前運行的");
}
@AfterMethod
public void afterMethod(){
System.out.println("執行afterMethod,這是在測試方法之後運行的");
}
@BeforeClass
public void beforeClass(){
System.out.println("執行beforeClass,這是在類運行之前運行的方法");
}
@AfterClass
public void afterClass(){
System.out.println("afterClass,這是在類運行之後運行的方法");
}
@BeforeSuite
public void beforeSuite(){
System.out.println("BeforeSuite測試套件");
}
@AfterSuite
public void afterSuite() {
System.out.println("AfterSuite測試套件");
}
}
運行結果如下: