Tdd Bdd Gherkin

Using behavior-driven development and Gherkin syntax to align business goals with technical tests.

jcorpac b154c74 2 files · 1.7 KB Updated

File contents

BDD & Gherkin

Behavior-Driven Development (BDD) encourages collaboration between developers, QA, and non-technical stakeholders.

Gherkin Syntax

Tests are written in plain English using the Given, When, Then format:

  • Scenario: A specific behavior being tested.
  • Given: The initial context or state.
  • When: An event or action occurs.
  • Then: The expected outcome or consequence.

Example Feature File

Feature: User Login

  Scenario: Successful login with valid credentials
    Given the user is on the login page
    When they enter "valid_user" and "valid_password"
    And they click the login button
    Then they should be redirected to the dashboard
    And they should see a "Welcome back" message

Best Practices

  1. Focus on Outcomes: Spend more time on the Then than the When.
  2. Avoid Technical Details: Feature files should not mention buttons, IDs, or implementation details.
  3. Collaborate Early: Write feature files with the product owner before coding starts.

jcorpac/ai-skills-library/tree/main/tdd/tdd-bdd-gherkin commit b154c74e69

Frequently asked questions

npx skillmds@latest add jcorpac/tdd-bdd-gherkin