Upgrade to Pro — share decks privately, control downloads, hide ads and more …

An Introduction to BDD

An Introduction to BDD

When a customer asks for a new feature to an application or a whole new application, how do you know where to start? Do you start writing production code right away? How do you know the code you are writing is taking you down the correct path? How do you know the code you are writing fulfills your customer's business problem? How do you know the code you are writing will stay correct when your customer asks for another new feature or you fix a bug in another part of the application? Unit testing has been a concept around for quite a while. It ensures that the code you write is logically correct and stays correct. The problem is that the stake holders of this new feature can not read your code and ensure that it is correct before you write your production code. Another problem is that unit testing is something that you do after you write your code. It is an afterthought and does not prevent you from writing the wrong code conceptually. The third problem is that stake holders often frown upon this. They hear the word "testing" and they think that it is something that can be skipped or bolted on later. What if you wrote your tests first? What if your customers could read your code like specifications? If so, then these should not be called "tests", but rather specifications. This "test first development" is called BDD or "behavior driven development". It allows your customers to read your tests as specifications in English phrases. It allows the developers to travel down the correct path and not write code that is not needed or wrong. In this session, we will review what BDD is and why you should adopt this concept in your next project. We will discuss and implement a feature from concept to implementation from the real world. We will then write this feature out using Ruby, Rails, and a BDD framework called Cucumber.

Jamie Wright

September 26, 2011
Tweet

More Decks by Jamie Wright

Other Decks in Programming

Transcript

  1. 3

  2. How do you verify what you are building is the

    thing that the customer wants? 6
  3. 56% of all bugs can be traced to errors made

    during the requirements stage -- Tom DeMarco 7
  4. Feature: In order to As a I want to Feature

    name / identifier Value proposition Role / Actor Feature description Feature: Add an item to my cart In order to purchase an item As an online shopper I want to place something in my cart to show intent that I plan on purchasing it 22
  5. Scenario: Given When Then Acceptance criteria Setup (arrange) User action

    / change occurs (act) Outcome (assert) Scenario: A user without an account can add items to their cart Given I do not have an account And a product exists with name: “Ton-Ton Sleeping bag” When I browse to the product’s detail page And I click “Add to Cart” Then I should be on the cart page And I should have an item in my cart with name: “Ton-Ton Sleeping bag” 23
  6. 43