如何在 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"); }
廣告