Using BDD for good

Alex Ivanova
Nov 21, 2019 · 6 min read

Using BDD to create the examples is amazing!

Ok. So how do we do this?

codecept generate:feature bdd search
Feature: Search
As a visitor
I want to search for paths
In order to find the one that I am interested in

Here is the template for writing BDD test cases

Scenario Outline: Visitor can find a path
Given I am a visitor
When I am on the "search" page
And I filter by <category>
And I search by <keyword>
Then I see the correct <path>
Examples:
| category | keyword | path |
| "paths" | "dev" | "Web Developer" |
| "paths" | "ai" | "AI Engineer" |
codecept dry-run bdd search.feature
codecept gherkin:snippets bdd
/**
* @Given I am a visitor
*/
/**
* @When I am on the :page page
*/
/**
* @When I filter by :category
*/
/**
* @When I search by :keyword
*/
/**
* @Then I should see the correct :path
*/
gherkin:
contexts:
default:
— BddTester
/**
* @Given I am a visitor
*/
public function iAmAVisitor()
{
$this->setLocale('en');
}
/**
* @When I am on the :page page
*/
public function iAmOnThePage($page)
{
$this->amOnPage($page);
}
/**
* @When I filter by :category
*/
public function iFilterByCategory($category = 'all')
{
$this->searchPage->addCategoryFilter($category);
}
Photo by Paul Hanaoka

How specific should we get?

To BDD or not to BDD?

Benefits of using BDD

Disadvantages of BDD

Summary

PS

Tech@OpenClassrooms

Tech@OpenClassrooms

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store