如何为 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+ 查看次数

开启你的 职业生涯

通过完成该课程获得认证

开始吧
广告