bdd with behat
TRANSCRIPT
BDD with Behat
Who am I?
Richard D [email protected]@IamPersistentFreelancerSymfony2 developerWanna 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 codeEliminates 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
AdvantagesClarifies 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
Write the code
Watch it pass
Write step for result
Watch it fail
Write the code
Watch it pass
Unit Testing
Does not replace unit testing,It supplements it
More complex
Scenario Outlines
Backgrounds
Hooks
In-step calls
New feature
Learn more
http://en.wikipedia.org/wiki/Behavior_Driven_Developmenthttp://blog.dannorth.net/introducing-bddhttps://github.com/aslakhellesoy/cucumber/wikihttp://cukes.infohttp://everzet.com/Behathttps://github.com/everzet/Behathttp://www.pragprog.com/titles/achbd/the-rspec-bookhttp://scotland-on-rails.s3.amazonaws.com/1A06_JosephWilk-SOR.mp4
Click to edit the title text format
Click to edit the title text format