Keeping your codebase as cool as a Cucumber


Tanya Powell / @tanya_powell

What is Behaviour Driven Development (BDD)?

BDD in Nutshell (Photo Credit: It's a Delivery Thing)

U w0t Mate

  • Imagine we are making a simple calculator that only adds two small numbers together
  • We can assume that we display: 2 + 2 = 4
  • Actually our domain expert expected our calculator to display: 2 + 2 = FOUR
Our Assumption Implemented The Expectation Implemented
When we print out addTwoNumbers(2, 2) we will be returned 4 Our answer will now be returned as FOUR

BDD vs TDD

Behaviour Driven Development (BDD) Test Driven Development (TDD)
  • Customer friendly language, e.g. $(count).should_be(5)
  • Expresses what the application needs to do for the stakeholder to find acceptable
  • Ensures the right application is built
  • Developer friendly language assertEquals(count, 5)
  • Aimed for developers to help them check their software designs
  • Ensures you build the application correctly

How to use BDD?

Cucumber Logo

Can be used with:

Ruby Java Python Javascript
Clojure .NET PHP C++

Gherkin

Gherkin
  • Cucumber's Domain Specific Language that allows you to describe the expected behaviour
  • Its two purposes are documentation and automated tests

Gherkin Keywords

Feature Background Scenario Given
When Then And But
* Scenario Outline Examples

Simple Feature Template (Feature Injection)


In order to { meet some goal }

As a { type of stakeholder }

I want { a feature }

Scenario: Adding Two Numbers

Writing The Tests

Results

Why use BDD?

  • It's simple and can improve team communication
  • The developer will know what to build
  • The tester will know what to test
  • The domain expert knows what bahaviour to expect

Thanks for listening

http://tanyapowell.co.uk/intro-to-bdd-talk/

You can talk to me here @tanya_powell