如何將測試方法納入執行並從 TestNG 中的一組測試用例中移除這些方法?
我們可以在 testng xml 檔案中藉助 <groups> 標記納入和移除測試方法以進行執行。
範例
Testng xml 檔案。
<?xml version = "1.0" encoding = "UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name = "Tutorialspoint Test "> <test name = "Test Cycle"> <groups> <run> <include name = "Smoke"/> <exclude name = "CodingModule"/> </run> </groups> <classes> <class name = "TestRegularExpression" /> </classes> </test> </suite>
testNG xml 中的組Smoke 要包含,組 CodingModule 要從執行中排除。
範例
@Test(groups={"Smoke"})
public void ContactDetails(){
System.out.println(“Contact details verification is successful”);
}
@Test(groups={"CodingModule"})
public void verifyInvoice(){
System.out.println(“Invoice verification is successful”);
}在一個 Java 類檔案中,組用來確定測試方法。擁有組 Smoke 的測試方法會新增到執行中,CodingModule 會從執行中排除。所以,ContactDetails() 測試方法將執行,但 verifyInvoice() 將不會執行。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
安卓
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP