SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Code Quality Assurance v4 (2013)
Code Quality Assurance v4 (2013)Code Quality Assurance v4 (2013)
Code Quality Assurance v4 (2013)
Peter Kofler
 
Behavior Driven GUI Testing
Behavior Driven GUI TestingBehavior Driven GUI Testing
Behavior Driven GUI Testing
Reginald Stadlbauer
 

Was ist angesagt? (20)

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

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

BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
Wen-Tien Chang
 

Ähnlich wie It's all about behaviour, also in php - phpspec (20)

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

Mehr von Giulio De Donato

Leaphly fight monolothic today
Leaphly fight monolothic todayLeaphly fight monolothic today
Leaphly fight monolothic today
Giulio De Donato
 

Mehr von Giulio De Donato (12)

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

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

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