Webinar BDD Behat
Webinar BDD Behat
Webinar BDD Behat
1 / 28
Co-founder of
Qafoo
passion for software quality
http://qafoo.com
Expert consulting Individual training Get your team bootstrapped with BDD effectively!
2 / 28
How to do a project
Some time later
Project
Awesome Shop
Smartphone
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
0 articles 0.00
Comments
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor.
Mess
Unit Tests
Selenium
No, no, no !
BDD with Behat 3 / 28
4 / 28
Developer
5 / 28
Unit Testing
6 / 28
Unit tests?
7 / 28
Stability
Unit Tests
Coverage
BDD with Behat 8 / 28
Outline
9 / 28
Behat
BDD test framework for PHP Inspired by Rubys Cucumber Work with Gherkin language framework
http://behat.org
10 / 28
Gherkin
Domain Specic Language (DSL) framework Goal: Business readable Create custom DSL on Gherkin Tie test code to DSL sentences
11 / 28
Gherkin in Action
1 2 3 4 5 6
Feature : DateTime proceeds t o end o f month . Scenario : Given When Then End o f February i s reached i t i s date 2013 02 01 I proceed t o t h e end o f t h e month t h e date i s 2013 02 28
12 / 28
Gherkin keywords
Given
Precondition Test setup
When
Behavior trigger Test stimulus
Then
Expected behavior Describe observable result
13 / 28
1 2 3 4 5 6
Feature : DateTime proceeds t o end o f month . Scenario : Given When Then End o f February i s reached i t i s date 2013 02 01 I proceed t o t h e end o f t h e month t h e date i s 2013 02 28
1 2 3
{ }
14 / 28
Feature : DateTime proceeds t o end o f month . Scenario : Given When Then End o f February i s reached i t i s date 2013 02 01 I proceed t o t h e end o f t h e month t h e date i s 2013 02 28
1 2 3 4 5 6 7 8 9 10 11 12
{
protected $date ; /
@Given / i t i s date ( [ ] ) $ / / public function t he re Is Th eD a te ( $date ) { $ t h i s > date = new \ DateTime ( $date ) ; } }
15 / 28
Feature : DateTime proceeds t o end o f month . Scenario : Given When Then End o f February i s reached i t i s date 2013 02 01 I proceed t o t h e end o f t h e month t h e date i s 2013 02 28
1 2 3 4 5 6 7 8 9 10
{
/ @When / I proceed t o t h e end o f t h e month$ / / public function iProceedToTheEndOfTheMonth ( )
{
$ t h i s > date > modify ( l a s t day o f t h i s month ) ;
} }
16 / 28
Feature : DateTime proceeds t o end o f month . Scenario : Given When Then End o f February i s reached i t i s date 2013 02 01 I proceed t o t h e end o f t h e month t h e date i s 2013 02 28
1 2 3 4 5 6 7 8 9 10 11 12
{
/
@Then / t h e date i s ( ? P< date > [ ] ) $ / / public function theDateIsNow ( $date ) { \ PHPUnit Framework Assert : : a s s e r t E q u a l s ( $date , $ t h i s > date > f o r m a t ( Ymd ) ); }
17 / 28
DDD
Specication BDD
BDD with Behat
Test
18 / 28
Outline
19 / 28
Mink
http://mink.behat.org
20 / 28
Feature : Browse W i k i p e d i a Scenario : Given When And Then Scenario : Given When And And Then Search f r o n t page I am on / I f i l l i n s e a r c h I n p u t w i t h Kore I press se a rc hB u tt o n I should see Kore may r e f e r t o : Follow r e d i r e c t l i n k I am on / I f i l l i n s e a r c h I n p u t w i t h Kore I press se a rc hB u tt o n I f o l l o w Kore ( energy d r i n k ) t h e response s t a t u s code should be 200
21 / 28
Mink Behat-extension
Mink integration for Behat Pre-build sentences to browse pages Extensible with custom sentences
http://extensions.behat.org/mink
22 / 28
Attention!
However
Useful for system tests Awesome for refactoring!
http://bit.ly/behat_cc
23 / 28
@Given / I am logged i n as ( [ ] ) $ / /
public function iAmLoggedInAs ( $user )
{
$ t h i s > currentUsername = $user ; return array ( new Step \ Given ( I am on / ) , new Step \When( I f i l l i n username w i t h . $user . ) , new Step \When( I f i l l i n password w i t h t e s t ) , new Step \When( I press Login ) , );
11 12 13 14
24 / 28
Outline
25 / 28
Behat
Mink-Extension
Mink
Goutte Sahi
Application
26 / 28
Conclusion
Behat is a tool for BDD in PHP Behat + Mink = Awesome for refactoring
27 / 28
http://bit.ly/behat_cc
Another Behat intro:
http://bit.ly/behat_intro
Slides later:
http://talks.qafoo.com
Rent a web quality expert:
http://qafoo.com
28 / 28