如何在 Cucumber 中執行 pre 步 和 post 步測試方法?


藉助 Cucumber 中的 @Before 和 @After 鉤子,我們可以執行 pre 步和 post 步測試方法。

示例

特徵檔案。

Feature: Transaction Table
Scenario: Verify the monthly transactions
Given User is on the Payment Page

步驟定義包含帶有鉤子 @Before 和 @After 的方法。帶有鉤子 @Before 的測試方法將作為 pre 步執行,然後執行測試方法(naviagteToPayment() 方法),最後執行帶有鉤子 @After 的測試方法,這是 post 步。

示例

@Before
public void method1(){
   System.out.println("The precondition executed successfully");
}
@After
public void method2(){
   System.out.println("The postcondition executed successfully ");
}
@Given ("^User is on payment page$")
public void navigateToPayment(){
   System.out.println ("Payment screen navigation is successful");
}

更新於:2020 年 6 月 11 日

2K+ 次瀏覽

開啟你的 職業

透過完成課程來獲得認證

開始
廣告