如何為 Cucumber 使用測試執行器檔案執行測試?


我們可以為 Cucumber 使用測試執行器檔案執行測試。測試執行器檔案應包含我們想要執行的功能檔案和步驟定義檔案的路徑。

功能檔案的程式碼實現

功能 ;− 登入模組

場景 歡迎頁面登入驗證

假定使用者在歡迎頁面

然後應該顯示歡迎頁面

示例

步驟定義檔案的程式碼實現

package stepDefinations;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
public class stepDefination {
   @Given("^User is on Welcome Page$")
   public void user_on_welcome_page() {
      System.out.println("User on welcome page");
   }
   @Then("^Welcome page should be displayed$")
   public void verify_user_on_welcome_page() {
      System.out.println("User should be on welcome page");
   }
}

測試執行器檔案的程式碼實現

package cucumberOptions;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
@RunWith(Cucumber.class)
@CucumberOptions(
   //path of feature file
   features = "src/test/java/features/Login.feature",
   //path of step definition file
   glue = "stepDefination"
   )
public class TestRunner {
}

專案結構

更新日期:2021 年 11 月 22 日

16K+ 檢視次數

開啟你的 職業生涯

透過完成該課程獲得認證

開始吧
廣告
© . All rights reserved.