Loading...
Loading...
Compare original and translation side by side
| Style | Example |
|---|---|
| ❌ Imperative | |
| ✅ Declarative | |
| Style | Example |
|---|---|
| ❌ Imperative | |
| ✅ Declarative | |
| 风格 | 示例 |
|---|---|
| ❌ 命令式 | |
| ✅ 声明式 | |
| 风格 | 示例 |
|---|---|
| ❌ 命令式 | |
| ✅ 声明式 | |
Feature: Order confirmation
Background:
Given an authenticated buyer has added items to the cart
And the cart meets the minimum order value
Scenario: Order confirmed and email sent
When the buyer completes the checkout process
Then the order status is "confirmed"
And a confirmation email is sent to the buyer
Scenario: Order confirmed without email if buyer has opted out
Given the buyer has disabled marketing emails
When the buyer completes the checkout process
Then the order status is "confirmed"
And no confirmation email is sentFeature: Order confirmation
Background:
Given an authenticated buyer has added items to the cart
And the cart meets the minimum order value
Scenario: Order confirmed and email sent
When the buyer completes the checkout process
Then the order status is "confirmed"
And a confirmation email is sent to the buyer
Scenario: Order confirmed without email if buyer has opted out
Given the buyer has disabled marketing emails
When the buyer completes the checkout process
Then the order status is "confirmed"
And no confirmation email is sentScenario Outline: Registration rejects invalid email formats
Given a new user is on the registration page
When the user attempts to register with email "<invalid_email>"
Then the registration fails
And an error message "Invalid email format" is displayed
Examples:
| invalid_email |
| notanemail |
| missing@domain |
| @domainonly.com |
| spaces in@email.com |Scenario Outline: Registration rejects invalid email formats
Given a new user is on the registration page
When the user attempts to register with email "<invalid_email>"
Then the registration fails
And an error message "Invalid email format" is displayed
Examples:
| invalid_email |
| notanemail |
| missing@domain |
| @domainonly.com |
| spaces in@email.com || Reusable step style | Example |
|---|---|
| Good reusable step | |
| Too specific to reuse | |
| 可复用步骤风格 | 示例 |
|---|---|
| 良好的可复用步骤 | |
| 过于具体无法复用 | |
GivenWhenThenAndButButBackgroundAndAndGivenWhenThenGivenWhenThenAndButButBackgroundAndAndGivenWhenThen| Coverage Type | Required | Description |
|---|---|---|
| Happy Path | Yes | Primary successful flow from start to finish |
| Business Rule Validation | Yes | Boundary values, role permissions, state transitions, allowed vs. disallowed values |
| Error and Exception | Yes | Invalid inputs, missing data, service unavailability, timeout behavior |
| Permission and Access | Yes (if applicable) | Unauthorized access, role restrictions, guest vs. authenticated flows |
| Data Integrity | Yes (if applicable) | Persistence, consistency, rollback, duplicate handling |
| Performance and Timing | Conditional | Only when the original requirement specifies time thresholds or load conditions |
| Accessibility | Conditional | Only when the original requirement specifies WCAG, screen reader, or assistive tech needs |
| Security | Conditional | Only when the original requirement specifies auth, encryption, audit, or data protection |
| 覆盖类型 | 是否必需 | 描述 |
|---|---|---|
| 快乐路径 | 是 | 从开始到结束的主要成功流程 |
| 业务规则验证 | 是 | 边界值、角色权限、状态转换、允许/不允许的值 |
| 错误与异常 | 是 | 无效输入、缺失数据、服务不可用、超时行为 |
| 权限与访问 | 是(如适用) | 未授权访问、角色限制、访客 vs 已认证用户流程 |
| 数据完整性 | 是(如适用) | 持久化、一致性、回滚、重复处理 |
| 性能与计时 | 可选 | 仅当原始需求指定时间阈值或负载条件时 |
| 可访问性 | 可选 | 仅当原始需求指定WCAG、屏幕阅读器或辅助技术需求时 |
| 安全性 | 可选 | 仅当原始需求指定认证、加密、审计或数据保护时 |
WhenWhenThenThenBackgroundWhenWhenThenThenBackgroundundefinedundefinedundefinedundefinedundefinedundefined| Input | Expected Outcome |
|---|---|
| <value 1> | <outcome 1> |
| <value 2> | <outcome 2> |
undefined| Input | Expected Outcome |
|---|---|
| <value 1> | <outcome 1> |
| <value 2> | <outcome 2> |
undefinedundefinedundefinedundefinedundefinedundefinedundefined| Scenario | Type | Rule Validated |
|---|---|---|
| Scenario 1 | Happy Path | <Primary success flow> |
| Scenario 2 | Business Rule | <Specific rule or boundary> |
| Scenario 3 | Sad Path | <Specific error or failure> |
| ... | ... | ... |
| Coverage Check | Status |
|---|---|
| Happy Path present | ✅ / ❌ |
| Business Rule scenario(s) present | ✅ / ❌ |
| Sad Path scenario(s) present | ✅ / ❌ |
| All scenarios independently executable | ✅ / ❌ |
| No implementation details in steps | ✅ / ❌ |
| No ambiguous or vague language | ✅ / ❌ |
undefined| Scenario | Type | Rule Validated |
|---|---|---|
| Scenario 1 | Happy Path | <主要成功流程> |
| Scenario 2 | Business Rule | <特定规则或边界> |
| Scenario 3 | Sad Path | <特定错误或失败> |
| ... | ... | ... |
| 覆盖检查项 | 状态 |
|---|---|
| 包含快乐路径 | ✅ / ❌ |
| 包含业务规则场景 | ✅ / ❌ |
| 包含异常路径场景 | ✅ / ❌ |
| 所有场景可独立执行 | ✅ / ❌ |
| 步骤中无实现细节 | ✅ / ❌ |
| 无模糊或歧义语言 | ✅ / ❌ |
undefinedTBD thresholdTBD threshold| Anti-Pattern | Why It Fails | Correct Approach |
|---|---|---|
| Imperative steps with UI actions | Brittle, not reusable, describes implementation not behavior | Use declarative steps that describe outcomes |
| Multiple When steps in one scenario | Violates "one scenario, one behavior" — causes confusion about what is being tested | Split into separate scenarios |
| Vague Then outcomes | Cannot be verified — ambiguous pass/fail | State exact expected observable outcome |
| Criteria with "and then" chaining multiple outcomes | Makes it unclear which assertion failed | Split outcomes into separate Then steps or separate scenarios |
| Using "should" or "could" | Describes a possibility rather than a requirement | Use "must" language or state the actual expected behavior |
| Including production data values | Introduces real data risk and makes scenarios non-reusable | Use representative, fictional example data |
| Describing UI layout or component names | Ties criteria to implementation, breaks when UI changes | Describe the capability, not the interface |
| Writing criteria before understanding the domain rule | Produces technically correct but semantically wrong criteria | Ask clarification questions first |
| 反模式 | 失败原因 | 正确做法 |
|---|---|---|
| 包含UI操作的命令式步骤 | 脆弱、不可复用,描述的是实现而非行为 | 使用描述结果的声明式步骤 |
| 单个场景包含多个When步骤 | 违反“一个场景对应一种行为”的规则,导致测试内容混淆 | 拆分为单独的场景 |
| 模糊的Then结果 | 无法验证,通过/失败结果不明确 | 明确说明预期的可观察结果 |
| 准则中使用“and then”串联多个结果 | 无法明确哪个断言失败 | 将结果拆分为单独的Then步骤或单独的场景 |
| 使用“should”或“could” | 描述的是可能性而非需求 | 使用“must”表述或说明实际预期行为 |
| 包含生产数据值 | 引入真实数据风险,场景无法复用 | 使用代表性的虚构示例数据 |
| 描述UI布局或组件名称 | 将准则与实现绑定,UI变更时准则失效 | 描述能力而非界面 |
| 在理解领域规则前编写准则 | 生成技术上正确但语义错误的准则 | 先提出澄清问题 |
email "user@example.com"amount "1000.00"code "ABC123"ThenThen an error message "Email format is invalid" is displayedauthenticated useradministratorguestsystem actorbuyeroperatorTBD thresholdemail "user@example.com"amount "1000.00"code "ABC123"Then an error message "Email format is invalid" is displayedauthenticated useradministratorguestsystem actorbuyeroperatorTBD threshold