Improve your product requirements process with Behavior-Driven Development & gherkin

An overview of Behavior-Driven Development & the gherkin syntax

By Rob Johnson

Thu Apr 21 2022

#tools

Behavior-driven development is very effective at distilling complex feature requests down to the essentials and can often help clear up misconceptions about processes, or desired features of a complex system.

It provides an approach of writing user stories in pseudocode which provides clarity to both the stakeholders and the developers.

I've been in situations where I've had several members of the same team around the table, discussing a current process each of them are involved in.

Writing in this style made clear that each of team members had different opinions of what and how the process should be performed.

This approach helped us to get a clear picture of what the requirements should be, whereas without this clarity, there could have been expensive additional iterations and corrections to the software which frustrate both the stakeholder and the developer.

Here is an example of a feature written in BDD using Gherkin syntax.

Feature:
Give new customers a free trial when signing up for a subscription

Scenario:
A customer signs up for a subscription that costs $5 per month which includes a 14-day free trial for new subscribers

Given a customer creates a new subscription and has not subscribed before
When they finish checkout, their subscription service starts immediately
And they are not charged for the subscription
Then after 14 days, they are automatically charged $5
And a new "next_charge_scheduled_at" date is set for the same day of the month in the following month
Then each renewal updates the "next_charge_scheduled_at" date

Given a customer cancels their subscription
Then the subscription status is set to "canceled"

# If a customer is past the free trial period
When the subscription has passed the free trial period
Then the membership service is set to expire when the current payment cycle ends
And the customer is not refunded for any previous payments (by default)

# If a customer is still within the free trial period
When the subscription has not passed the free trial period
Then their service expires after the free trial period ends
And the customer is not charged for any subsequent renewals

Even if I'm the only one writing the software, this approach can save countless hours of pointless coding by distilling down the core functionality while reviewing "bugs" in my own logic.

Learn more about BDD


# tools 5 # sql 3 # javascript 10 # projects 4 # css 2 # git 2 # php 3 # analytics 4 # monitoring 2 # commerce 9 # seo 4 # api 3 # shopify 4 # python 2 # aws 2