You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

确认Cucumber/Gherkin两种Data Table写法的执行流程是否正确

两种Gherkin写法的执行流程验证

你的理解是完全正确的,以下是两种写法的具体执行逻辑:

写法1:步骤内嵌入Data Table

Given that the user has access to the server

When sending a server_info request with the following parameters:
"""
id = <id>
user = <user>
"""
| id     | user  |
| 0      | userA |
| 1      | userB |
| 2      | userC |

Then the server will return the <user> and status
  • 执行流程:
    • 先执行Given步骤完成前置准备
    • When步骤会一次性接收整个Data Table作为参数,遍历表格中的3组数据,连续发送3次server_info请求
    • 所有请求发送完毕后,才进入Then步骤执行响应验证
    • 整个场景仅执行1次,如果服务器响应会被新请求覆盖,Then步骤只能获取最后一组参数(id=2、user=userC)的响应结果

写法2:Scenario Outline + Examples

Given that the user has access to the server

When sending a server_info request with the following parameters:
"""
id = <id>
user = <user>
"""
Then the server will return the <user> and status
   Examples:
   | id     | user  |
   | 0      | userA |
   | 1      | userB |
   | 2      | userC |
  • 执行流程:
    • 这是Scenario Outline的标准用法,Examples表格中的每一行数据都会触发一次完整的场景执行
    • 第一组数据:执行Given→发送1次请求→执行Then验证响应
    • 第二组数据:重新执行Given初始化前置→发送1次请求→执行Then验证响应
    • 第三组数据:重复上述流程
    • 整个场景总计执行3次,每次验证的都是当前请求的响应,不会被后续请求覆盖

内容的提问来源于stack exchange,提问作者bob_the_builder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 04:42:47