如何在 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");
}
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP