TestNG測試套件

1、執行順序
public class BasicAnnotation {
//最基本的註解,用來把方法標記爲測試的一部分;
@Test
public void testCase1(){
System.out.println(“這是測試用例1”);
}
@BeforeMethod
public void beforeMethod(){
System.out.println(“BeforeMethod這是在測試方法之前運行的”);
}
@Test
public void testCase2(){
System.out.println(“test這是測試用例2”);
}
@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測試套件”);
}
}
執行結果:
這裏寫圖片描述

2、測試套件
–組織測試類一起執行的或者一組行爲的測試用例的集合;

–在TestNG中,無法在測試源碼中定義一個套件,可以由一個XML文件表示,因爲套件是執行的功能,還允許靈活配置要運行的測試。

–套件可以包含一個或多個測試,並由標記定義。

是testng.xml的根標記。 它描述了一個測試套件,它又由幾個部分組成。

下表列出了接受的所有定義的合法屬性。

屬性 描述
name 套件的名稱,這是一個強制屬性。
verbose 運行的級別或詳細程度。
parallel TestNG是否運行不同的線程來運行這個套件。
thread-count 如果啓用並行模式(忽略其他方式),則要使用的線程數。
annotations 在測試中使用的註釋類型。
time-out 在本測試中的所有測試方法上使用的默認超時。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章