bdd-scenarios
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBDD Scenarios
BDD 场景编写
Learn to write clear, maintainable BDD scenarios that effectively capture business requirements and drive implementation.
学习编写清晰、可维护的BDD场景,有效捕捉业务需求并指导开发实现。
Writing Good Scenarios
编写优质场景的要点
A good scenario should be:
- Specific: Test one behavior
- Declarative: Describe what, not how
- Business-focused: Use domain language
- Independent: No dependencies on other scenarios
gherkin
undefined优质场景应具备以下特点:
- 具体明确:仅测试单一行为
- 声明式表述:描述结果而非实现方式
- 聚焦业务:使用领域专属语言
- 独立无依赖:不依赖其他场景
gherkin
undefinedGood scenario - specific and declarative
Good scenario - specific and declarative
Scenario: Customer receives loyalty discount
Given a customer with Gold membership status
And a cart total of $100
When the customer proceeds to checkout
Then a 10% loyalty discount should be applied
And the final total should be $90
Scenario: Customer receives loyalty discount
Given a customer with Gold membership status
And a cart total of $100
When the customer proceeds to checkout
Then a 10% loyalty discount should be applied
And the final total should be $90
Bad scenario - too implementation-focused
Bad scenario - too implementation-focused
Scenario: Apply discount
Given I click the membership dropdown
And I select "Gold" from the list
When I click the checkout button
Then the JavaScript calculates 10% off
undefinedScenario: Apply discount
Given I click the membership dropdown
And I select "Gold" from the list
When I click the checkout button
Then the JavaScript calculates 10% off
undefinedAcceptance Criteria Format
验收标准格式
gherkin
Feature: Order Refunds
# Rule-based acceptance criteria
Rule: Full refunds are available within 30 days
Scenario: Refund requested within return window
Given an order placed 15 days ago
When the customer requests a refund
Then a full refund should be processed
Scenario: Refund requested after return window
Given an order placed 45 days ago
When the customer requests a refund
Then the refund should be denied
And the customer should see "Return window expired"gherkin
Feature: Order Refunds
# Rule-based acceptance criteria
Rule: Full refunds are available within 30 days
Scenario: Refund requested within return window
Given an order placed 15 days ago
When the customer requests a refund
Then a full refund should be processed
Scenario: Refund requested after return window
Given an order placed 45 days ago
When the customer requests a refund
Then the refund should be denied
And the customer should see "Return window expired"Edge Case Scenarios
边缘案例场景
gherkin
Feature: User Registration
Scenario: Successful registration
Given I am on the registration page
When I submit valid registration details
Then my account should be created
# Edge cases
Scenario: Registration with existing email
Given a user exists with email "existing@example.com"
When I try to register with email "existing@example.com"
Then I should see "Email already registered"
Scenario: Registration with invalid email format
When I try to register with email "not-an-email"
Then I should see "Please enter a valid email"
Scenario: Registration with empty required fields
When I submit the registration form with empty fields
Then I should see validation errors for required fieldsgherkin
Feature: User Registration
Scenario: Successful registration
Given I am on the registration page
When I submit valid registration details
Then my account should be created
# Edge cases
Scenario: Registration with existing email
Given a user exists with email "existing@example.com"
When I try to register with email "existing@example.com"
Then I should see "Email already registered"
Scenario: Registration with invalid email format
When I try to register with email "not-an-email"
Then I should see "Please enter a valid email"
Scenario: Registration with empty required fields
When I submit the registration form with empty fields
Then I should see validation errors for required fieldsScenario Tags and Organization
场景标签与组织管理
gherkin
@authentication @critical
Feature: User Login
@smoke
Scenario: Basic login flow
# ...
@security
Scenario: Account lockout after failed attempts
# ...
@wip
Scenario: Two-factor authentication
# Work in progressgherkin
@authentication @critical
Feature: User Login
@smoke
Scenario: Basic login flow
# ...
@security
Scenario: Account lockout after failed attempts
# ...
@wip
Scenario: Two-factor authentication
# Work in progressWhen to Use This Skill
何时使用该技能
Use bdd-scenarios when you need to:
- Define acceptance criteria for user stories
- Document expected system behavior
- Create comprehensive test coverage
- Identify edge cases early in development
- Communicate requirements clearly
当你需要以下操作时,可使用BDD场景编写技能:
- 为用户故事定义验收标准
- 记录系统预期行为
- 实现全面的测试覆盖
- 在开发早期识别边缘案例
- 清晰传达需求
Best Practices
最佳实践
- Start with the happy path scenario
- Add edge cases systematically
- Use tags for organization and filtering
- Keep scenarios at 3-7 steps
- Write scenarios before implementation
- Review scenarios with stakeholders
- 从正常流程场景入手
- 系统地添加边缘案例
- 使用标签进行组织和筛选
- 每个场景保持3-7个步骤
- 在开发前编写场景
- 与相关人员评审场景
Common Pitfalls
常见误区
- Writing scenarios after implementation
- Including too many steps per scenario
- Using vague or ambiguous language
- Forgetting negative test cases
- Not organizing with tags effectively
- 在开发完成后才编写场景
- 单个场景包含过多步骤
- 使用模糊或歧义的表述
- 遗漏负面测试案例
- 未有效利用标签进行组织