Skip to main content

BDD (Behavior Driven Development)

What is BDD?

The Given-When-Then syntax is a commonly used structure for writing user stories and acceptance criteria in behavior-driven development (BDD). It is used to describe the desired behavior of a system in a clear, concise, and consistent manner.

The structure is broken down into three parts:

  • Given: This section describes the initial state or context of the system. It sets the scene for the scenario being tested.
  • When: This section describes the action or event that occurs. It specifies the trigger for the scenario being tested.
  • Then: This section describes the expected outcome or result of the scenario. It defines the acceptance criteria for the scenario being tested.

Example:

Given a user is on the login page
When the user enters their username and password and clicks the login button
Then the user should be directed to the home page.
*** Test Cases ***
Login With Admin
Given I am on the login page
When I login with username "admin" and password "admin"
Then I should see the welcome page

Login With Invalid User
Given I am on the login page
When I login with username "invalid" and password "invalid"
Then I should see the error message
And I should be able to login again
Let me run it