BDD with Behat
Who am I? Richard D Shank [email_address] @IamPersistent Freelancer Symfony2 developer Wanna be rock star
What is BDD? Behavior Driven Development
What is BDD? What does that mean?
Testing We know we should do it, why don't we? It takes too much time
It slows me down
The boss won't let me
I'm not really sure how
Testing Write code
Write tests The test is written to match code
It carries the bias of our code
Its just too much trouble
TDD Solution: Test Driven Development
TDD Test written  before  code Eliminates bias
You know the test will be written
TDD What the hell do I test?
BDD Behavior Driven Development
BDD What makes it different? Its written from the outside in, driven by the business value
BDD How does it work? You tell a story When a customer clicks on a blue widget, it is added to their shopping cart.
BDD Advantages Clarifies up front what needs to be done
It is written in everyday, spoken language
Anyone can understand and write stories
Makes everyone think about the requirements
It keeps you focused on what is necessary - YAGNI
Gherkin
Behat System to write and test stories
Uses Gherkin syntax
6 step process
PHP 5.3
Installation $ pear channel-discover pear.everzet.com $ pear install everzet/behat-beta
File organization
Step 1 - Behavior addition.feature
Step 2 – Object Definition Steps are generated Calculator.php
Step 2 – Object Definition *Writing a stub class is not really the BDD way of doing things, PHP doesn't handle 'method not found' exceptions very well, so the stub class is necessary for PHP
Step 2 – Generate Steps
Step 2 – Step Definition steps/calculator.php
Step 2 – Add support support/env.php
Step 3 - Write a definition
Step 4 – Run it, watch it  fail
Step 5 – Write the code
Step 6 – Run it, watch it  pass!
Wash, rinse, repeat Keep repeating the process  until all tests pass.
Write step for add
Watch it  fail

BDD with Behat