如何在 Cucumber 中設定測試方法的執行順序?
我們可以藉助 order 關鍵字在 Cucumber 中設定測試方法的執行順序。測試方法在步驟定義檔案中分配順序。
具有較低順序的測試方法先執行,然後執行具有較高順序的方法。
示例
步驟定義檔案。
@Before (order = 1) public void login(){ System.out.println("login is successful"); } @Before (order = 2) public void payment(){ System.out.println("payment is successful"); } @Given ("^Land in repayment page$") public void repay(){ System.out.println ("Actual Scenario of repayment"); }
具有較低順序(login() 設定為 1)的測試方法將首先執行。然後,將執行具有更高順序的 payment() 測試方法。
這些方法成功執行後,將執行測試方法 repay()。
廣告