SlideShare una empresa de Scribd logo
1 de 16
Descargar para leer sin conexión
DRI Code Sessions
●   TDD - Test Driven Development


Introduction to TDD, Unit Testing and some
  short examples in PHP with PHPUnit.




    Content by Rogério Vicente under the Creative Commons License
TDD – What is it?
●   Software Development technique
●   Short development cycle
●   Write tests before any production code
●   Write only the minimum amount of code
     required to pass the tests
●   It's great for code documentation
TDD Cycle




Image from Wikipedia
Common excuses
●   “We have no time to write tests”
●   “Testing is boring”
●   “My code is good enough”
●   “That's not my job, tests are for QA
      Department”
●   “This is just something simple. It's not
      worth it”
TDD - Pros
●   Some studies conclude that TDD raises
     productivity – less time spent debugging
●   Makes programmers focus on interface
     before implementation
●   Provides greater level of confidence in the
     code
●   Can lead to more modularized, flexible and
     extensible code
●   Tests are a source of documentation
TDD - Cons
●   Difficult to use with GUI's and code that
     works with databases
●   Badly written tests become a burden to
     maintain
●   Specs misinterpretation leads to wrong
     tests and wrong code
●   Management support is crucial
Unit Testing

●   Not TDD
●   Part of TDD
●   Unit = The smallest testable part of an
     application
Unit Testing


  “Whenever you are tempted to type
 something into a print statement or a
debugger expression, write it as a test
              instead.”

            Martin Fowler
Unit Testing Frameworks in PHP


●   PHPUnit
●   SimpleTest
PHPUnit
●   http://www.phpunit.de
●   PEAR Package
●   Created by Sebastian Bergmann
●   Port of Junit (Java)
●   Regression test framework to implement
     unit tests in PHP
SimpleTest
●   http://www.lastcraft.com/simple_test.php
●   Created by Marcus Baker
●   Can test web interfaces
●   Cute web interface for displaying test
     results
Code Examples




Let's see some code, but first...
Some Cool Game
●   Contract:
       –   Player life points
               ●   Is initially 100
               ●   Cannot become negative
               ●   Cannot be more than 150
●   Interface:
       –   getLife()
       –   setLife($value)
       –   gainLife($value)
       –   loseLife($value)
Code Samples

              Download available at:
              http://whit.me/dricodesessionstdd

              Or fork and improve it:
git clone http://github.com/rogeriopvl/dri_codesessions_tdd
References

●   http://en.wikipedia.org/wiki/Test_driven_development
●   http://en.wikipedia.org/wiki/Unit_testing
●   http://www.viddler.com/explore/RoyOsherove/videos/19/
●   http://www.slideshare.net/Skud/test-driven-development-tutoria
●   http://artofunittesting.com/
●   http://xunitpatterns.com
The End




Questions?

Más contenido relacionado

La actualidad más candente

Lighning Talk: PHP build process
Lighning Talk: PHP build processLighning Talk: PHP build process
Lighning Talk: PHP build process
Bryan Agee
 
Behaviour Testing and Continuous Integration with Drupal
Behaviour Testing and Continuous Integration with DrupalBehaviour Testing and Continuous Integration with Drupal
Behaviour Testing and Continuous Integration with Drupal
smithmilner
 
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
VincitOy
 
JAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone before
JAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone beforeJAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone before
JAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone before
jazoon13
 

La actualidad más candente (20)

Continuous Integration In Php
Continuous Integration In PhpContinuous Integration In Php
Continuous Integration In Php
 
Lighning Talk: PHP build process
Lighning Talk: PHP build processLighning Talk: PHP build process
Lighning Talk: PHP build process
 
User story workflow (eng)
User story workflow (eng)User story workflow (eng)
User story workflow (eng)
 
21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir
21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir
21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir
 
Automatic Test 2019-07-25
Automatic Test 2019-07-25Automatic Test 2019-07-25
Automatic Test 2019-07-25
 
Project Management: Burn-Down Chart / OrangeHRM Project MOD (eng)
Project Management: Burn-Down Chart / OrangeHRM Project MOD (eng)Project Management: Burn-Down Chart / OrangeHRM Project MOD (eng)
Project Management: Burn-Down Chart / OrangeHRM Project MOD (eng)
 
Behaviour Testing and Continuous Integration with Drupal
Behaviour Testing and Continuous Integration with DrupalBehaviour Testing and Continuous Integration with Drupal
Behaviour Testing and Continuous Integration with Drupal
 
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
 
The automation of the process of caring for the quality of the code in PHP an...
The automation of the process of caring for the quality of the code in PHP an...The automation of the process of caring for the quality of the code in PHP an...
The automation of the process of caring for the quality of the code in PHP an...
 
MSL2008. Debugging
MSL2008. DebuggingMSL2008. Debugging
MSL2008. Debugging
 
C++ and Software Engineering 2015
C++ and Software Engineering 2015C++ and Software Engineering 2015
C++ and Software Engineering 2015
 
Leaning on the two Ts
Leaning on the two TsLeaning on the two Ts
Leaning on the two Ts
 
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
 
TDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and GomegaTDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and Gomega
 
JAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone before
JAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone beforeJAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone before
JAZOON'13 - Andres Almiray - Spock: boldly go where no test has gone before
 
Introduction to Spock: A Unit Testing Framework
Introduction to Spock: A Unit Testing FrameworkIntroduction to Spock: A Unit Testing Framework
Introduction to Spock: A Unit Testing Framework
 
Test-Driven Development with TypeScript+Jasmine+AngularJS
Test-Driven Development with TypeScript+Jasmine+AngularJSTest-Driven Development with TypeScript+Jasmine+AngularJS
Test-Driven Development with TypeScript+Jasmine+AngularJS
 
Test your user interface using BDD (Swedish)
Test your user interface using BDD (Swedish)Test your user interface using BDD (Swedish)
Test your user interface using BDD (Swedish)
 
Developer Job in Practice
Developer Job in PracticeDeveloper Job in Practice
Developer Job in Practice
 
Android tdd
Android tddAndroid tdd
Android tdd
 

Destacado (7)

Objektorientierte Programmierung mit extbase und fluid
Objektorientierte Programmierung mit extbase und fluidObjektorientierte Programmierung mit extbase und fluid
Objektorientierte Programmierung mit extbase und fluid
 
Stand das im Handbuch?
Stand das im Handbuch?Stand das im Handbuch?
Stand das im Handbuch?
 
Extbase and Beyond
Extbase and BeyondExtbase and Beyond
Extbase and Beyond
 
Test-Driven Development for TYPO3
Test-Driven Development for TYPO3Test-Driven Development for TYPO3
Test-Driven Development for TYPO3
 
Test-Driven Development for TYPO3 @ T3CON12DE
Test-Driven Development for TYPO3 @ T3CON12DETest-Driven Development for TYPO3 @ T3CON12DE
Test-Driven Development for TYPO3 @ T3CON12DE
 
Semantic TYPO3
Semantic TYPO3Semantic TYPO3
Semantic TYPO3
 
Test-Driven Development with FLOW3
Test-Driven Development with FLOW3Test-Driven Development with FLOW3
Test-Driven Development with FLOW3
 

Similar a Test Driven Development with PHP

Why every Tester should also aspire to be a Developer on his project!-Sandee...
Why every Tester should  also aspire to be a Developer on his project!-Sandee...Why every Tester should  also aspire to be a Developer on his project!-Sandee...
Why every Tester should also aspire to be a Developer on his project!-Sandee...
bhumika2108
 

Similar a Test Driven Development with PHP (20)

Test driven development_continuous_integration
Test driven development_continuous_integrationTest driven development_continuous_integration
Test driven development_continuous_integration
 
Test-Driven Development.pptx
Test-Driven Development.pptxTest-Driven Development.pptx
Test-Driven Development.pptx
 
Unit testing (eng)
Unit testing (eng)Unit testing (eng)
Unit testing (eng)
 
Introduction to Test Automation
Introduction to Test AutomationIntroduction to Test Automation
Introduction to Test Automation
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
 
Debugging 2013- Lars pedersen
Debugging 2013- Lars pedersenDebugging 2013- Lars pedersen
Debugging 2013- Lars pedersen
 
Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application Deployment
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
 
Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy
 
Passing the Joel Test in the PHP World (phpbnl10)
Passing the Joel Test in the PHP World (phpbnl10)Passing the Joel Test in the PHP World (phpbnl10)
Passing the Joel Test in the PHP World (phpbnl10)
 
Why every Tester should also aspire to be a Developer on his project!-Sandee...
Why every Tester should  also aspire to be a Developer on his project!-Sandee...Why every Tester should  also aspire to be a Developer on his project!-Sandee...
Why every Tester should also aspire to be a Developer on his project!-Sandee...
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
Codeception: introduction to php testing
Codeception: introduction to php testingCodeception: introduction to php testing
Codeception: introduction to php testing
 
UPC Plone Testing Talk
UPC Plone Testing TalkUPC Plone Testing Talk
UPC Plone Testing Talk
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)
 
Clean application development (talk)
Clean application development (talk)Clean application development (talk)
Clean application development (talk)
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy Code
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
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
 

Último (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Test Driven Development with PHP

  • 1. DRI Code Sessions ● TDD - Test Driven Development Introduction to TDD, Unit Testing and some short examples in PHP with PHPUnit. Content by Rogério Vicente under the Creative Commons License
  • 2. TDD – What is it? ● Software Development technique ● Short development cycle ● Write tests before any production code ● Write only the minimum amount of code required to pass the tests ● It's great for code documentation
  • 4. Common excuses ● “We have no time to write tests” ● “Testing is boring” ● “My code is good enough” ● “That's not my job, tests are for QA Department” ● “This is just something simple. It's not worth it”
  • 5. TDD - Pros ● Some studies conclude that TDD raises productivity – less time spent debugging ● Makes programmers focus on interface before implementation ● Provides greater level of confidence in the code ● Can lead to more modularized, flexible and extensible code ● Tests are a source of documentation
  • 6. TDD - Cons ● Difficult to use with GUI's and code that works with databases ● Badly written tests become a burden to maintain ● Specs misinterpretation leads to wrong tests and wrong code ● Management support is crucial
  • 7. Unit Testing ● Not TDD ● Part of TDD ● Unit = The smallest testable part of an application
  • 8. Unit Testing “Whenever you are tempted to type something into a print statement or a debugger expression, write it as a test instead.” Martin Fowler
  • 9. Unit Testing Frameworks in PHP ● PHPUnit ● SimpleTest
  • 10. PHPUnit ● http://www.phpunit.de ● PEAR Package ● Created by Sebastian Bergmann ● Port of Junit (Java) ● Regression test framework to implement unit tests in PHP
  • 11. SimpleTest ● http://www.lastcraft.com/simple_test.php ● Created by Marcus Baker ● Can test web interfaces ● Cute web interface for displaying test results
  • 12. Code Examples Let's see some code, but first...
  • 13. Some Cool Game ● Contract: – Player life points ● Is initially 100 ● Cannot become negative ● Cannot be more than 150 ● Interface: – getLife() – setLife($value) – gainLife($value) – loseLife($value)
  • 14. Code Samples Download available at: http://whit.me/dricodesessionstdd Or fork and improve it: git clone http://github.com/rogeriopvl/dri_codesessions_tdd
  • 15. References ● http://en.wikipedia.org/wiki/Test_driven_development ● http://en.wikipedia.org/wiki/Unit_testing ● http://www.viddler.com/explore/RoyOsherove/videos/19/ ● http://www.slideshare.net/Skud/test-driven-development-tutoria ● http://artofunittesting.com/ ● http://xunitpatterns.com