SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
Zend PHP Conference - Santa Clara, US
      Derick Rethans - dr@ez.no
   http://derickrethans.nl/talks.php
About Me

●   Dutchman living in Norway
●   eZ Systems A.S.
●   eZ Components project lead
●   PHP development
●   mcrypt, input_filter, date/time support, unicode
●   QA
Introduction


It's OK to write code that does not work
It's OK to write code that does not work
Introduction


  About Testing
Web Application Testing
                Testable Parts

Front-end
   ● Acceptance Tests and System Tests that run in the


     browser
   ● Testing of Web Services with Unit Tests

   ● Compatibility Testing for Browser/OS/etc. combinations

   ● Performance Testing

   ● Security Testing


Back-end
   ● Functional Testing of business logic with Unit Tests

   ● Reusable Components, but they often come with their


     own tests
Testing Methods

Unit Testing
Tests small parts of an application or library (units) for
correctly working code. Tools: PHPUnit, SimpleTest

System Testing
The testing of a whole integrated system against the
specified requirements. Tools: Selenium

Non-functional Testing
Testing for performance, load, stress, reliability, availability,
security. Tools: ab, siege, httperf, chorizo
Test-Driven Development
a feature without a test is not a feature
Test-Driven Development




It is not just a method of testing
             software.
Test-Driven Development




  It is a religion.




✡✝☪
Back In Time
                Traditional Development Phases

Requirements Specification
Define what the software is supposed to do.

Design
Define how the software is supposed to be implemented.

Implementation
The implementation of the software itself.

Testing
The implemented software is tested.
Sometimes.
 
Tests are King

Tests drive the development
  ● Tests are written before the code

  ● There is no code without tests




Test Suites
  ● Contain tests that check whether the code does what it


    is supposed to do
  ● Also cover things that should fail
Into the Future
                Test-Driven Development Phases

Requirements Specification
Define what the software is supposed to do.

Design
Define how the software is supposed to be implemented.

Implementation ≡ Testing
The implemented software is tested.
The implementation of the software itself.
Test-Driven Development
               eZ Components Development

Present the Idea
Write the Requirements Document
Design the Component
Implementation
  ● Write API stubs with parameter documentation and


    descriptions
  ● Write test cases

  ● Initial implementation

  ● Initial implementation review

  ● Updating implementation according to review

  ● Implementation review


Pre-release Testing
Test-Driven Development
                 Addressing Defects

Write Test Case
Write a test case to test the correct behavior of the method,
and verify that the test case fails

Fix the Issue
Fix the implementation

Verify Fix with Test Case
Make sure that the test cases pass with the new
implementation

Check Other Test Cases
Verify that the fix for this defect did not break any other test
case
The Way of Testivus

  ●   If you write code, write tests.
   ● Don’t get stuck on unit testing dogma.

   ● Embrace unit testing karma.

   ● Think of code and test as one.

   ● The test is more important than the unit.

   ● The best time to test is when the code is fresh.

   ● Tests not run waste away.

   ● An imperfect test today is better than a perfect test


      someday.
   ● An ugly test is better than no test.

   ● Sometimes, the test justifies the means.

   ● Only fools use no tools.

   ● Good tests fail.


http://www.artima.com/weblogs/viewpost.jsp?thread=203994
 
PHP Unit
PHPUnit
Unit Testing Framework for PHP
PHPUnit
Code Coverage: No Code Without Test
PHPUnit
               Code Coverage: No Code Without Test




Green: Covered code.
Red: Not covered code.
Grey: Unreachable code.
White: No code.
PHPUnit
                Code Coverage: How important?

< 100% Coverage ≡ Not fully tested code
100% Coverage ≢ Fully tested code


How much coverage should you aim for?
  ● It doesn't matter, just write some tests.

  ● How much rice do I need to cook?

  ● 100%, and no less!




http://www.developertesting.com/archives/month200705/200
70504-000425.html
phpUnderControl
Continuous integration with CruiseControl
Un-testable Problems

●   Testing singletons more than one time
●   System/Operating System dependent tests
●   Private methods
●   Code that depends on the state of an external resource
●   Things that simply should never happen
Politics
resistance to change
Developers

Fear - more work to do
  ● Introduce TDD concepts gently

  ● Whenever a problem is found, make and retain a test


    case for futher use
  ● Start using TDD for new projects
Managers

Ignorance - too much time spent on testing
   ● Out of date with modern processes

   ● Belief that testing slows the schedule (only if you follow


     the ship-and-see process)
   ● You save time later, because you wouldn't have to re-


     test or re-debug newly written additions or big fixes.
 
Case Studies
Case Studies

Microsoft Case Study
   ● TDD project has twice the code quality

   ● Writing tests requires 15% more time


IBM Case Study
   ● 40% fewer defects

   ● No impact on the team's productivity


John Deere / Ericsson Case Study
   ● TDD produces higher quality code

   ● Impact of 16% on the team's productivity
Case Studies
                Developer Comments

●   At first I didn't like that I need to write tests for my code,
    but now after using it for more than 10 months I can't
    program without it.
●   Helps to come up with better APIs.
●   It gives confidence that our software is working well at
    all times. Even after making major changes and/or
    changing software we are dependent on.
●   Productivity increases - you might loose some when
    you make the initial tests, but you'll get it back later. The
    code covered by tests is 'insured' against future
    changes.
●   It works well for libraries, not so well for GUI
    applications.
●   Some things cannot be tested like server errors, unless
    you use mock-objects.
Questions




        ?
Resources

http://homepage.mac.com/hey.you/lessons.html
Testuvius: http://www.artima.com/weblogs/viewpost.jsp?
thread=203994



PHP Unit: http://phpunit.de
phpUnderControl: http://phpundercontrol.org
Xdebug: http://xdebug.org
These Slides: http://derickrethans.nl/talks.php


PHP: http://www.php.net

Contenu connexe

Tendances

30 of the best free software test tools in 60 minutes by Jess Lancaster
30 of the best free software test tools in 60 minutes by Jess Lancaster30 of the best free software test tools in 60 minutes by Jess Lancaster
30 of the best free software test tools in 60 minutes by Jess Lancaster
QA or the Highway
 
Automating good coding practices
Automating good coding practicesAutomating good coding practices
Automating good coding practices
Kevin Peterson
 

Tendances (20)

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Myths and reality about software testing
Myths and reality about software testingMyths and reality about software testing
Myths and reality about software testing
 
Unit testing for project managers
Unit testing for project managersUnit testing for project managers
Unit testing for project managers
 
30 of the best free software test tools in 60 minutes by Jess Lancaster
30 of the best free software test tools in 60 minutes by Jess Lancaster30 of the best free software test tools in 60 minutes by Jess Lancaster
30 of the best free software test tools in 60 minutes by Jess Lancaster
 
Automating good coding practices
Automating good coding practicesAutomating good coding practices
Automating good coding practices
 
Sustainable Automation Frameworks by Kelsey Shannahan
Sustainable Automation Frameworks by Kelsey ShannahanSustainable Automation Frameworks by Kelsey Shannahan
Sustainable Automation Frameworks by Kelsey Shannahan
 
Continuous everything
Continuous everythingContinuous everything
Continuous everything
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and Automation
 
Selenium Testing Project report
Selenium Testing Project reportSelenium Testing Project report
Selenium Testing Project report
 
Continuous Automated Regression Testing to the Rescue
Continuous Automated Regression Testing to the RescueContinuous Automated Regression Testing to the Rescue
Continuous Automated Regression Testing to the Rescue
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Developer + tester = quality++
Developer + tester = quality++Developer + tester = quality++
Developer + tester = quality++
 
Presentation_TDD
Presentation_TDDPresentation_TDD
Presentation_TDD
 
End-to-End Test Automation for Both Horizontal and Vertical Scale
End-to-End Test Automation for Both Horizontal and Vertical ScaleEnd-to-End Test Automation for Both Horizontal and Vertical Scale
End-to-End Test Automation for Both Horizontal and Vertical Scale
 
5 top pain points of test automation
5 top pain points of test automation5 top pain points of test automation
5 top pain points of test automation
 
Topic production code
Topic production codeTopic production code
Topic production code
 
Software Characterization & Performance Testing - Beat Your Software with a S...
Software Characterization & Performance Testing - Beat Your Software with a S...Software Characterization & Performance Testing - Beat Your Software with a S...
Software Characterization & Performance Testing - Beat Your Software with a S...
 
АНТОН МУЖАЙЛО «Test Team Development and Management Techniques»
АНТОН МУЖАЙЛО «Test Team Development and Management Techniques»АНТОН МУЖАЙЛО «Test Team Development and Management Techniques»
АНТОН МУЖАЙЛО «Test Team Development and Management Techniques»
 
Roman iovlev battle - JDI vs Selenide - Selenium Camp
Roman iovlev battle - JDI vs Selenide - Selenium CampRoman iovlev battle - JDI vs Selenide - Selenium Camp
Roman iovlev battle - JDI vs Selenide - Selenium Camp
 
Software Testing, Everyone's responsibility
Software Testing, Everyone's responsibilitySoftware Testing, Everyone's responsibility
Software Testing, Everyone's responsibility
 

En vedette (7)

Wprowadzenie do PHPUnit
Wprowadzenie do PHPUnitWprowadzenie do PHPUnit
Wprowadzenie do PHPUnit
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best Practices
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to hero
 
Test-Driven Development (TDD)
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)
 

Similaire à Test Driven Development

Automated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra SolutionsAutomated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra Solutions
Quontra Solutions
 

Similaire à Test Driven Development (20)

Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development Introduction
 
Automated tests
Automated testsAutomated tests
Automated tests
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Introduction of unit test to management
Introduction of unit test to managementIntroduction of unit test to management
Introduction of unit test to management
 
Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To Testing
 
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
Developers’ mDay u Banjoj Luci - Milan Popović, PHP Srbija – Testimony (about...
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
Automated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra SolutionsAutomated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra Solutions
 
Test
TestTest
Test
 
Tools for Software Testing
Tools for Software TestingTools for Software Testing
Tools for Software Testing
 
End-end tests as first class citizens - SeleniumConf 2020
End-end tests as first class citizens - SeleniumConf 2020End-end tests as first class citizens - SeleniumConf 2020
End-end tests as first class citizens - SeleniumConf 2020
 
Future of QA
Future of QAFuture of QA
Future of QA
 
Futureofqa
FutureofqaFutureofqa
Futureofqa
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 

Plus de ZendCon

Plus de ZendCon (20)

Framework Shootout
Framework ShootoutFramework Shootout
Framework Shootout
 
Zend_Tool: Practical use and Extending
Zend_Tool: Practical use and ExtendingZend_Tool: Practical use and Extending
Zend_Tool: Practical use and Extending
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i Tutorial
 
PHP on Windows - What's New
PHP on Windows - What's NewPHP on Windows - What's New
PHP on Windows - What's New
 
PHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudPHP and Platform Independance in the Cloud
PHP and Platform Independance in the Cloud
 
I18n with PHP 5.3
I18n with PHP 5.3I18n with PHP 5.3
I18n with PHP 5.3
 
Cloud Computing: The Hard Problems Never Go Away
Cloud Computing: The Hard Problems Never Go AwayCloud Computing: The Hard Problems Never Go Away
Cloud Computing: The Hard Problems Never Go Away
 
Planning for Synchronization with Browser-Local Databases
Planning for Synchronization with Browser-Local DatabasesPlanning for Synchronization with Browser-Local Databases
Planning for Synchronization with Browser-Local Databases
 
Magento - a Zend Framework Application
Magento - a Zend Framework ApplicationMagento - a Zend Framework Application
Magento - a Zend Framework Application
 
Enterprise-Class PHP Security
Enterprise-Class PHP SecurityEnterprise-Class PHP Security
Enterprise-Class PHP Security
 
PHP and IBM i - Database Alternatives
PHP and IBM i - Database AlternativesPHP and IBM i - Database Alternatives
PHP and IBM i - Database Alternatives
 
Zend Core on IBM i - Security Considerations
Zend Core on IBM i - Security ConsiderationsZend Core on IBM i - Security Considerations
Zend Core on IBM i - Security Considerations
 
Application Diagnosis with Zend Server Tracing
Application Diagnosis with Zend Server TracingApplication Diagnosis with Zend Server Tracing
Application Diagnosis with Zend Server Tracing
 
Insights from the Experts: How PHP Leaders Are Transforming High-Impact PHP A...
Insights from the Experts: How PHP Leaders Are Transforming High-Impact PHP A...Insights from the Experts: How PHP Leaders Are Transforming High-Impact PHP A...
Insights from the Experts: How PHP Leaders Are Transforming High-Impact PHP A...
 
Solving the C20K problem: Raising the bar in PHP Performance and Scalability
Solving the C20K problem: Raising the bar in PHP Performance and ScalabilitySolving the C20K problem: Raising the bar in PHP Performance and Scalability
Solving the C20K problem: Raising the bar in PHP Performance and Scalability
 
Joe Staner Zend Con 2008
Joe Staner Zend Con 2008Joe Staner Zend Con 2008
Joe Staner Zend Con 2008
 
Tiery Eyed
Tiery EyedTiery Eyed
Tiery Eyed
 
Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...
Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...
Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...
 
DB2 Storage Engine for MySQL and Open Source Applications Session
DB2 Storage Engine for MySQL and Open Source Applications SessionDB2 Storage Engine for MySQL and Open Source Applications Session
DB2 Storage Engine for MySQL and Open Source Applications Session
 
Digital Identity
Digital IdentityDigital Identity
Digital Identity
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+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@
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
+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...
 
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
 
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
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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...
 
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
 
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
 

Test Driven Development

  • 1. Zend PHP Conference - Santa Clara, US Derick Rethans - dr@ez.no http://derickrethans.nl/talks.php
  • 2. About Me ● Dutchman living in Norway ● eZ Systems A.S. ● eZ Components project lead ● PHP development ● mcrypt, input_filter, date/time support, unicode ● QA
  • 3. Introduction It's OK to write code that does not work
  • 4. It's OK to write code that does not work
  • 6. Web Application Testing Testable Parts Front-end ● Acceptance Tests and System Tests that run in the browser ● Testing of Web Services with Unit Tests ● Compatibility Testing for Browser/OS/etc. combinations ● Performance Testing ● Security Testing Back-end ● Functional Testing of business logic with Unit Tests ● Reusable Components, but they often come with their own tests
  • 7. Testing Methods Unit Testing Tests small parts of an application or library (units) for correctly working code. Tools: PHPUnit, SimpleTest System Testing The testing of a whole integrated system against the specified requirements. Tools: Selenium Non-functional Testing Testing for performance, load, stress, reliability, availability, security. Tools: ab, siege, httperf, chorizo
  • 8. Test-Driven Development a feature without a test is not a feature
  • 9. Test-Driven Development It is not just a method of testing software.
  • 10. Test-Driven Development It is a religion. ✡✝☪
  • 11. Back In Time Traditional Development Phases Requirements Specification Define what the software is supposed to do. Design Define how the software is supposed to be implemented. Implementation The implementation of the software itself. Testing The implemented software is tested. Sometimes.
  • 12.  
  • 13. Tests are King Tests drive the development ● Tests are written before the code ● There is no code without tests Test Suites ● Contain tests that check whether the code does what it is supposed to do ● Also cover things that should fail
  • 14. Into the Future Test-Driven Development Phases Requirements Specification Define what the software is supposed to do. Design Define how the software is supposed to be implemented. Implementation ≡ Testing The implemented software is tested. The implementation of the software itself.
  • 15. Test-Driven Development eZ Components Development Present the Idea Write the Requirements Document Design the Component Implementation ● Write API stubs with parameter documentation and descriptions ● Write test cases ● Initial implementation ● Initial implementation review ● Updating implementation according to review ● Implementation review Pre-release Testing
  • 16. Test-Driven Development Addressing Defects Write Test Case Write a test case to test the correct behavior of the method, and verify that the test case fails Fix the Issue Fix the implementation Verify Fix with Test Case Make sure that the test cases pass with the new implementation Check Other Test Cases Verify that the fix for this defect did not break any other test case
  • 17. The Way of Testivus ● If you write code, write tests. ● Don’t get stuck on unit testing dogma. ● Embrace unit testing karma. ● Think of code and test as one. ● The test is more important than the unit. ● The best time to test is when the code is fresh. ● Tests not run waste away. ● An imperfect test today is better than a perfect test someday. ● An ugly test is better than no test. ● Sometimes, the test justifies the means. ● Only fools use no tools. ● Good tests fail. http://www.artima.com/weblogs/viewpost.jsp?thread=203994
  • 18.  
  • 21. PHPUnit Code Coverage: No Code Without Test
  • 22. PHPUnit Code Coverage: No Code Without Test Green: Covered code. Red: Not covered code. Grey: Unreachable code. White: No code.
  • 23. PHPUnit Code Coverage: How important? < 100% Coverage ≡ Not fully tested code 100% Coverage ≢ Fully tested code How much coverage should you aim for? ● It doesn't matter, just write some tests. ● How much rice do I need to cook? ● 100%, and no less! http://www.developertesting.com/archives/month200705/200 70504-000425.html
  • 25. Un-testable Problems ● Testing singletons more than one time ● System/Operating System dependent tests ● Private methods ● Code that depends on the state of an external resource ● Things that simply should never happen
  • 27. Developers Fear - more work to do ● Introduce TDD concepts gently ● Whenever a problem is found, make and retain a test case for futher use ● Start using TDD for new projects
  • 28. Managers Ignorance - too much time spent on testing ● Out of date with modern processes ● Belief that testing slows the schedule (only if you follow the ship-and-see process) ● You save time later, because you wouldn't have to re- test or re-debug newly written additions or big fixes.
  • 29.  
  • 31. Case Studies Microsoft Case Study ● TDD project has twice the code quality ● Writing tests requires 15% more time IBM Case Study ● 40% fewer defects ● No impact on the team's productivity John Deere / Ericsson Case Study ● TDD produces higher quality code ● Impact of 16% on the team's productivity
  • 32. Case Studies Developer Comments ● At first I didn't like that I need to write tests for my code, but now after using it for more than 10 months I can't program without it. ● Helps to come up with better APIs. ● It gives confidence that our software is working well at all times. Even after making major changes and/or changing software we are dependent on. ● Productivity increases - you might loose some when you make the initial tests, but you'll get it back later. The code covered by tests is 'insured' against future changes. ● It works well for libraries, not so well for GUI applications. ● Some things cannot be tested like server errors, unless you use mock-objects.
  • 34. Resources http://homepage.mac.com/hey.you/lessons.html Testuvius: http://www.artima.com/weblogs/viewpost.jsp? thread=203994 PHP Unit: http://phpunit.de phpUnderControl: http://phpundercontrol.org Xdebug: http://xdebug.org These Slides: http://derickrethans.nl/talks.php PHP: http://www.php.net