如何在 TestNG 中為每個測試方法執行一個先決條件方法和一個後置條件方法?
利用 @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 類檔案中,帶有 @BeforeMethod 的 prerequisite() 方法將作為每個測試方法的先決條件執行。然後執行 loanPay(),最後帶有 @AfterMethod 的 postcondition() 方法將執行。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP