SlideShare a Scribd company logo
IT’S ALL ABOUT BEHAVIOUR
-ALSO IN PHP@liuggio
PUG-ROMA 26-02-2013
WHY WE DO TESTS?

> refactor
> automation
> verification
> ??
WHO LOVES TDD?
"Test-Driven Development is a developer practice
that involves writing tests before writing the code
being tested."

<<TDD is a design tool
used to deliver high-quality code >>

REFACTOR IS TIME CONSUMING
TDD: THE INFINTE CYCLE

RED

GREEN

REFACTOR
TDD: THE INFINTE CYCLE
"Run it, watch it fail, write just enough
code to get it to pass, review the design,
and remove duplication" > "Run it, watch it
fail, write just enough code to get it to pass,
review the design, and remove duplication" >
"Run it, watch it fail, write just enough code to get it to pass,
review the design, and remove duplication" > "Run it, watch it fail,
write just enough code to get it to pass, review the design, and remove
duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and
remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove
duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just
enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough
code to get it to pass, review the design, and remove duplication"

TECHNOLOGIC
TDD: mmm
If you have a blank project, you have to start...
Where to start?
What to test?
What not to test?
How much tests?
Where to start?
TDD: mmmmmmmmm
“If you need to test the insertion of an object into a
collection and the collection is represented by an
Array, with xUnit you should assert that the
collection contains the object in the Array, but if the
collection will change to another type of container,
graph for example, the xUnit will fail, even if the
behaviour is unchanged. “
BDD :)
in BDD you are not testing
you are describing what that classes will do,
so you can continue creating the class
Specify the Behaviour by Examples
not testing a class.
BDD :D
External behaviour - Story
Behat deals to have specifications that reflects
the environment from the outside.
Solve: Where to start, What to and not to test
Internal behaviour - Example
PHPSpec responds to the behaviour in the lower
level, from the internal of the classes.
Solve all the TDD mmmmmmm
BDD the double cycle
1 start from Scenario
2 write a story that fail
go to phpspec2 internal level

3 write a fail Example
4 get it green
5 refactor
go to behat external level

7 refactor
"Spec BDD with phpspec
phpspec is a development tool, designed to help you achieve
clean and working PHP code by using a technique derived
from test-first development called (spec) behaviour driven
developement, or SpecBDD."
LET’S CODE
1. Installation composer

{
"require-dev": {
"phpspec/phpspec2": "*"
},
"config": {
"bin-dir": "bin"
},
"autoload": {"psr-0": {"": "src"}},
"minimum-stability": "dev"
}

2.

Code the behaviour: WAIT
we have to talk the same language
DEFINITION
In BDD you are going to 'Describe' the behaviour of a Class
creating a `Spec` that will contain more Examples.
'example' is the class to write, before write the subject code.
'expectation' the behaviour that the subject code should
have.

• Assertion becomes expectation.
• Test method becomes code example
• Test case becomes example group/Specification
CODING TIME
Not really coding, command lining :)
$ bin/phpspec desc FakeTwitter
Specification for FakeTwitter created in spec/FakeTwitter.php.

Now Code the examples ...
$ bin/phpspec run -v -f prettify
BDD
I Code, than I specify

BDD you're doing it wrong
Cool I'm going to
specify all my old
projects

BDD you're doing it wrong
I don't care about
documentation and
acceptance.

BDD you're doing it wrong
I don't need unit tests,
and I do not need to
specify

1987 developer
REFERENCES
- http://www.slideshare.net/bmabey/the-why-behind-tddbdd-and-the-how-with-rspec
- The RSpec Book: Behaviour-Driven Development with RSpec, Cucumber, and Friends
- http://www.slideshare.net/Robbert/bdd-rspec
- phpspec.net
- behat.org

More Related Content

PDF
BDD in PHP - Behat
ODP
BDD with Behat
PPTX
Behat - human-readable automated testing
PDF
really really really awesome php application with bdd behat and iterfaces
PPTX
BDD and Behave
PPTX
Php test fest
PDF
BDD Testing Using Godog - Bangalore Golang Meetup # 32
PPTX
Code Quality Assurance
BDD in PHP - Behat
BDD with Behat
Behat - human-readable automated testing
really really really awesome php application with bdd behat and iterfaces
BDD and Behave
Php test fest
BDD Testing Using Godog - Bangalore Golang Meetup # 32
Code Quality Assurance

What's hot (20)

PPTX
Integration of automation framework with ci tools
PPT
Code Quality
PDF
Code Quality Assurance v4 (2013)
ODP
Behavior Driven GUI Testing
PDF
Why and how to keep your code quality
PPTX
What Is Cucumber?
PPTX
Typescript kata The TDD style 2 edition
PDF
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
PDF
Detangling Your JavaScript
KEY
Javascript Tests with Jasmine for Front-end Devs
PPTX
Acceptance Test Driven Development and Robot Framework
PDF
BDD & Cucumber
PPTX
Test Driven Development in CQ5/AEM
PDF
TDD and Simple Design Workshop - Session 1 - March 2019
PDF
DDD with Behat
PPTX
Introduction to go lang
PDF
C++ and Software Engineering 2015
PDF
Dsl로 만나는 groovy
PDF
Why I Love Ruby On Rails
PDF
Why you should care about Go (Golang)
Integration of automation framework with ci tools
Code Quality
Code Quality Assurance v4 (2013)
Behavior Driven GUI Testing
Why and how to keep your code quality
What Is Cucumber?
Typescript kata The TDD style 2 edition
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
Detangling Your JavaScript
Javascript Tests with Jasmine for Front-end Devs
Acceptance Test Driven Development and Robot Framework
BDD & Cucumber
Test Driven Development in CQ5/AEM
TDD and Simple Design Workshop - Session 1 - March 2019
DDD with Behat
Introduction to go lang
C++ and Software Engineering 2015
Dsl로 만나는 groovy
Why I Love Ruby On Rails
Why you should care about Go (Golang)
Ad

Similar to It's all about behaviour, also in php - phpspec (20)

PDF
Don't let your tests slow you down
PDF
Bdd and-testing
PDF
Behaviour Driven Development and Thinking About Testing
 
PPTX
Understanding Why Testing is Importaint
PDF
BDD style Unit Testing
PPTX
TDD a piccoli passi
PDF
TDD reloaded - JUGTAA 24 Ottobre 2012
ODP
New Ideas for Old Code - Greach
KEY
Agile JavaScript Testing
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
PDF
Tdd is not about testing
PPTX
BDD testing with cucumber
PDF
Tdd in practice
PDF
2011-02-03 LA RubyConf Rails3 TDD Workshop
PDF
BDD Testing and Automating from the trenches - Presented at Into The Box June...
PDF
ITB2016 -BDD testing and automation from the trenches
PDF
TDD and BDD in Sky Deutschland
PDF
Spec(ing) Out Your Workflow with SpecFlow
PDF
Rspec and Capybara Intro Tutorial at RailsConf 2013
ODP
2014 11 20 Drupal 7 -> 8 test migratie
Don't let your tests slow you down
Bdd and-testing
Behaviour Driven Development and Thinking About Testing
 
Understanding Why Testing is Importaint
BDD style Unit Testing
TDD a piccoli passi
TDD reloaded - JUGTAA 24 Ottobre 2012
New Ideas for Old Code - Greach
Agile JavaScript Testing
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Tdd is not about testing
BDD testing with cucumber
Tdd in practice
2011-02-03 LA RubyConf Rails3 TDD Workshop
BDD Testing and Automating from the trenches - Presented at Into The Box June...
ITB2016 -BDD testing and automation from the trenches
TDD and BDD in Sky Deutschland
Spec(ing) Out Your Workflow with SpecFlow
Rspec and Capybara Intro Tutorial at RailsConf 2013
2014 11 20 Drupal 7 -> 8 test migratie
Ad

More from Giulio De Donato (12)

PPTX
Docker italia fatti un container tutto tuo
PDF
Lets isolate a process with no container like docker
PPTX
More developers on DevOps with Docker orchestration
PDF
Import golang; struct microservice
PDF
Json web token api authorization
PDF
Think horizontally ood, ddd and bdd
PDF
I came i saw i go - golang it meetup codemotion rome 2014
PDF
Benchmark Profile and Boost your Symfony application
PDF
Leaphly fight monolothic today
PDF
Design pattern in Symfony2 - Nanos gigantium humeris insidentes
PPT
Caching and data analysis will move your Symfony2 application to the next level
PDF
Rationally boost your symfony2 application with caching tips and monitoring
Docker italia fatti un container tutto tuo
Lets isolate a process with no container like docker
More developers on DevOps with Docker orchestration
Import golang; struct microservice
Json web token api authorization
Think horizontally ood, ddd and bdd
I came i saw i go - golang it meetup codemotion rome 2014
Benchmark Profile and Boost your Symfony application
Leaphly fight monolothic today
Design pattern in Symfony2 - Nanos gigantium humeris insidentes
Caching and data analysis will move your Symfony2 application to the next level
Rationally boost your symfony2 application with caching tips and monitoring

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
Teaching material agriculture food technology
PPTX
Cloud computing and distributed systems.
Reach Out and Touch Someone: Haptics and Empathic Computing
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
NewMind AI Weekly Chronicles - August'25 Week I
Mobile App Security Testing_ A Comprehensive Guide.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
The AUB Centre for AI in Media Proposal.docx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced Soft Computing BINUS July 2025.pdf
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Dropbox Q2 2025 Financial Results & Investor Presentation
GamePlan Trading System Review: Professional Trader's Honest Take
NewMind AI Monthly Chronicles - July 2025
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Chapter 3 Spatial Domain Image Processing.pdf
Teaching material agriculture food technology
Cloud computing and distributed systems.

It's all about behaviour, also in php - phpspec

  • 1. IT’S ALL ABOUT BEHAVIOUR -ALSO IN PHP@liuggio PUG-ROMA 26-02-2013
  • 2. WHY WE DO TESTS? > refactor > automation > verification > ??
  • 3. WHO LOVES TDD? "Test-Driven Development is a developer practice that involves writing tests before writing the code being tested." <<TDD is a design tool used to deliver high-quality code >> REFACTOR IS TIME CONSUMING
  • 4. TDD: THE INFINTE CYCLE RED GREEN REFACTOR
  • 5. TDD: THE INFINTE CYCLE "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" TECHNOLOGIC
  • 6. TDD: mmm If you have a blank project, you have to start... Where to start? What to test? What not to test? How much tests? Where to start?
  • 7. TDD: mmmmmmmmm “If you need to test the insertion of an object into a collection and the collection is represented by an Array, with xUnit you should assert that the collection contains the object in the Array, but if the collection will change to another type of container, graph for example, the xUnit will fail, even if the behaviour is unchanged. “
  • 8. BDD :) in BDD you are not testing you are describing what that classes will do, so you can continue creating the class Specify the Behaviour by Examples not testing a class.
  • 9. BDD :D External behaviour - Story Behat deals to have specifications that reflects the environment from the outside. Solve: Where to start, What to and not to test Internal behaviour - Example PHPSpec responds to the behaviour in the lower level, from the internal of the classes. Solve all the TDD mmmmmmm
  • 10. BDD the double cycle 1 start from Scenario 2 write a story that fail go to phpspec2 internal level 3 write a fail Example 4 get it green 5 refactor go to behat external level 7 refactor
  • 11. "Spec BDD with phpspec phpspec is a development tool, designed to help you achieve clean and working PHP code by using a technique derived from test-first development called (spec) behaviour driven developement, or SpecBDD."
  • 12. LET’S CODE 1. Installation composer { "require-dev": { "phpspec/phpspec2": "*" }, "config": { "bin-dir": "bin" }, "autoload": {"psr-0": {"": "src"}}, "minimum-stability": "dev" } 2. Code the behaviour: WAIT we have to talk the same language
  • 13. DEFINITION In BDD you are going to 'Describe' the behaviour of a Class creating a `Spec` that will contain more Examples. 'example' is the class to write, before write the subject code. 'expectation' the behaviour that the subject code should have. • Assertion becomes expectation. • Test method becomes code example • Test case becomes example group/Specification
  • 14. CODING TIME Not really coding, command lining :) $ bin/phpspec desc FakeTwitter Specification for FakeTwitter created in spec/FakeTwitter.php. Now Code the examples ... $ bin/phpspec run -v -f prettify
  • 15. BDD
  • 16. I Code, than I specify BDD you're doing it wrong
  • 17. Cool I'm going to specify all my old projects BDD you're doing it wrong
  • 18. I don't care about documentation and acceptance. BDD you're doing it wrong
  • 19. I don't need unit tests, and I do not need to specify 1987 developer
  • 20. REFERENCES - http://www.slideshare.net/bmabey/the-why-behind-tddbdd-and-the-how-with-rspec - The RSpec Book: Behaviour-Driven Development with RSpec, Cucumber, and Friends - http://www.slideshare.net/Robbert/bdd-rspec - phpspec.net - behat.org