SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
Test Driven Development



       An Introduction
              by
       Lukasz Kujawa
About Me
- Lukasz Kujawa

- Lead Developer at Gloople

- http://systemsarchitect.net/

- @lukaszkujawa
What is TDD?
"Test-driven development (TDD) is a software
development process that relies on the repetition of a
very short development cycle: first the developer writes
an (initially failing) automated test case that defines a
desired improvement or new function, then produces the
minimum amount of code to pass that test, and finally
refactors the new code to acceptable standards"
- Wikipedia
What is TDD in English?
Create test before code
TDD Cycle
RED
 GREEN
REFACTOR
The Three Laws of TDD
- You might not write production code until you
have written a failing unit test

- You might not write more of a unit test than is
sufficient to fail, and not compiling is failing

- You may not write more production code then
is sufficient to pass the currently failing test
TDD Iterations


  Test                       Production code
  Write minimal Unit Test    Create a Class
  Call method of the class   Create the Method
  Assert output of the       Add logic to return
  method                     expected output
Unit Testing
"In computer programming, unit testing is a method by
which individual units of source code, sets of one or more
computer program modules together with associated
control data, usage procedures, and operating procedures,
are tested to determine if they are fit for use."
- Wikipedia
Unit Testing in English
Testing smallest testable parts of application
Unit Test is not a Test
- Very narrow and well defined scope
- No complex dependencies
- Test only one application layer
- Environment independent
- Fast
TTD - Too Damn Difficult?
Benefits for Developer
- Confidence

- Code quality

- Time

- Refactoring

- Reopening issues

- Self documenting code
Benefits for Business
Benefits for Business
- Shorten development cycles

- Delivering more

- Stable products
Research 1
"Art of Unit Testing" by Roy Osherove

  Stage                  Team without tests   Team with tests
  Implementation         7 days               14 days
  (coding)
  Integration            7 days               2 days
  Testing / Bug Fixing   12 days              8 days
  Overall release time   26 days              24 days
  Bugs in production     71                   11
Research 2
Quality improvement through test driven
development: results and experiences of four
industrial teams (2008) by Nachiappan
Nagappan, E. Michael Maximilien, Thirumalesh
Bhat and Laurie Williams

http://biblio.gdinwiddie.
com/biblio/StudiesOfTestDrivenDevelopment
Research 2
 Metric             IBM Drivers   Microsoft:   Microsoft:   Microsoft: VS
 description                      Windows      MSN

 Defect density     W             X            Y            Z
 of comparable
 team in
 organization
 but not using
 TDD

 Defect density     0.61W         0.38X        0.24Y        0.09Z
 of team using
 TDD

 Increase in time   15-20%        25-35%       15%          20-25%
 taken to code
 the feature
 because
 of TDD (%)
How to test?
<?php

MyFramework::bootstrap();

$obj = new Class_Under_Test();

if( $obj->something('Foo') != 47 ) {
      throw new Exception('Incorrect output for Foo');
}

if( $obj->someting('Bar') !== false ) {
      throw new Exception('Incorrect output for Bar');
}
Unit Test Frameworks
- PHPUnit

- SimpleTest
Using Framework
- API

- No maintenance

- Integration with IDE

- Code coverage report

- Mocks
<?php

class MyClassTest extends PHPUnit_Framework_TestCase {

    public static function setUpBeforeClass() {
      MyFramework::initAutoloader();
    }

    protected function setUp() {
       $this->myClass = new MyClass();
    }

    public function testSomething() {
      $this->assertEquals(1, $this->myClass->something());
    }

    public function testSomethingElse() {
      $this->assertTrue( $this->myClass->somethingElse() );
      $this->assertFalse $this->myClass->somethingElse( 47 ) );
    }

}
PHPUnit - Eclipse integration
Unit Testing - small print
- Can't test directly private, protected and static
methods
- Tests only functionality
- Database
- Requires rigorous discipline
SHOULD I TRY IT?




YESREFACTOR
Q&A

Mais conteúdo relacionado

Mais procurados

Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)
Babul Mirdha
 

Mais procurados (20)

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Android Devops : Master Continuous Integration and Delivery
Android Devops : Master Continuous Integration and DeliveryAndroid Devops : Master Continuous Integration and Delivery
Android Devops : Master Continuous Integration and Delivery
 
Unit testing
Unit testing Unit testing
Unit testing
 
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Development
 
Testing in TFS
Testing in TFSTesting in TFS
Testing in TFS
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.
 
Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NET
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
QA Fest 2017. Владимир Примаков. QA метрики. Взгляд на качество с разных стор...
QA Fest 2017. Владимир Примаков. QA метрики. Взгляд на качество с разных стор...QA Fest 2017. Владимир Примаков. QA метрики. Взгляд на качество с разных стор...
QA Fest 2017. Владимир Примаков. QA метрики. Взгляд на качество с разных стор...
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development Introduction
 
Automation frameworks
Automation frameworksAutomation frameworks
Automation frameworks
 
Eclipse Day India 2015 - Eclipse RCP testing using Jubula based automation
Eclipse Day India 2015 - Eclipse RCP testing using Jubula based automationEclipse Day India 2015 - Eclipse RCP testing using Jubula based automation
Eclipse Day India 2015 - Eclipse RCP testing using Jubula based automation
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 
Automated Testing vs Manual Testing
Automated Testing vs Manual TestingAutomated Testing vs Manual Testing
Automated Testing vs Manual Testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 

Destaque

Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
Joshua Warren
 
From User Personas to Testing: A Project Manager's Journey Towards Behat
From User Personas to Testing: A Project Manager's Journey Towards BehatFrom User Personas to Testing: A Project Manager's Journey Towards Behat
From User Personas to Testing: A Project Manager's Journey Towards Behat
Design for Drupal, Boston
 

Destaque (20)

Introduccion al desarrollo guiado por comportamiento
Introduccion al desarrollo guiado por comportamientoIntroduccion al desarrollo guiado por comportamiento
Introduccion al desarrollo guiado por comportamiento
 
Code Dojo
Code DojoCode Dojo
Code Dojo
 
BDD with Behat and Symfony2
BDD with Behat and Symfony2BDD with Behat and Symfony2
BDD with Behat and Symfony2
 
BDD con Behat y Mink en Symfony2
BDD con Behat y Mink en Symfony2BDD con Behat y Mink en Symfony2
BDD con Behat y Mink en Symfony2
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
 
BDD with Behat and PHPSpec
BDD with Behat and PHPSpecBDD with Behat and PHPSpec
BDD with Behat and PHPSpec
 
From User Personas to Testing: A Project Manager's Journey Towards Behat
From User Personas to Testing: A Project Manager's Journey Towards BehatFrom User Personas to Testing: A Project Manager's Journey Towards Behat
From User Personas to Testing: A Project Manager's Journey Towards Behat
 
Automated tests to a REST API
Automated tests to a REST APIAutomated tests to a REST API
Automated tests to a REST API
 
Calidad de código en Chamilo: Behat, Travis-CI y Scrutinizer-CI
Calidad de código en Chamilo: Behat, Travis-CI y Scrutinizer-CICalidad de código en Chamilo: Behat, Travis-CI y Scrutinizer-CI
Calidad de código en Chamilo: Behat, Travis-CI y Scrutinizer-CI
 
To mock or not to mock
To mock or not to mockTo mock or not to mock
To mock or not to mock
 
SpecBDD in PHP
SpecBDD in PHPSpecBDD in PHP
SpecBDD in PHP
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
TDD with BDD in PHP and Symfony
TDD with BDD in PHP and SymfonyTDD with BDD in PHP and Symfony
TDD with BDD in PHP and Symfony
 
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
 
BDD & Behat for Srijan Technologies
BDD & Behat for Srijan TechnologiesBDD & Behat for Srijan Technologies
BDD & Behat for Srijan Technologies
 
Behat bdd training (php) course slides pdf
Behat bdd training (php) course slides pdfBehat bdd training (php) course slides pdf
Behat bdd training (php) course slides pdf
 
Behat: Beyond the Basics
Behat: Beyond the BasicsBehat: Beyond the Basics
Behat: Beyond the Basics
 
PhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesPhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examples
 
BDD in my team: how we do it
BDD in my team: how we do itBDD in my team: how we do it
BDD in my team: how we do it
 

Semelhante a Test driven development

Evaluating Test Driven Development And Parameterized Unit Testing In Dot Net ...
Evaluating Test Driven Development And Parameterized Unit Testing In Dot Net ...Evaluating Test Driven Development And Parameterized Unit Testing In Dot Net ...
Evaluating Test Driven Development And Parameterized Unit Testing In Dot Net ...
mdfachowdhury
 
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
 
Test Driven Development - Tulsa TechFest 2009
Test Driven Development - Tulsa TechFest 2009Test Driven Development - Tulsa TechFest 2009
Test Driven Development - Tulsa TechFest 2009
Jason Ragsdale
 
Test driven development
Test driven developmentTest driven development
Test driven development
Shalabh Saxena
 
Test Driven Development - 09/2009
Test Driven Development - 09/2009Test Driven Development - 09/2009
Test Driven Development - 09/2009
Jason Ragsdale
 

Semelhante a Test driven development (20)

Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
Python and test
Python and testPython and test
Python and test
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Evaluating Test Driven Development And Parameterized Unit Testing In Dot Net ...
Evaluating Test Driven Development And Parameterized Unit Testing In Dot Net ...Evaluating Test Driven Development And Parameterized Unit Testing In Dot Net ...
Evaluating Test Driven Development And Parameterized Unit Testing In Dot Net ...
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
 
Lecture #6. automation testing (andrey oleynik)
Lecture #6. automation testing (andrey oleynik)Lecture #6. automation testing (andrey oleynik)
Lecture #6. automation testing (andrey oleynik)
 
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
 
Continuous Testing
Continuous TestingContinuous Testing
Continuous Testing
 
TDD talk
TDD talkTDD talk
TDD talk
 
Test Driven Development - Tulsa TechFest 2009
Test Driven Development - Tulsa TechFest 2009Test Driven Development - Tulsa TechFest 2009
Test Driven Development - Tulsa TechFest 2009
 
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
tem7
tem7tem7
tem7
 
Test Driven Development - 09/2009
Test Driven Development - 09/2009Test Driven Development - 09/2009
Test Driven Development - 09/2009
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012
 
Waterfallacies V1 1
Waterfallacies V1 1Waterfallacies V1 1
Waterfallacies V1 1
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit testing
Unit testingUnit testing
Unit testing
 

Último

+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@
 
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
 
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
 
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)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
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
 
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
 
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
 
+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...
 
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...
 
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
 
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​
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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...
 
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
 
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
 
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
 
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
 
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
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.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...
 
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
 

Test driven development

  • 1. Test Driven Development An Introduction by Lukasz Kujawa
  • 2. About Me - Lukasz Kujawa - Lead Developer at Gloople - http://systemsarchitect.net/ - @lukaszkujawa
  • 3. What is TDD? "Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards" - Wikipedia
  • 4. What is TDD in English? Create test before code
  • 7. The Three Laws of TDD - You might not write production code until you have written a failing unit test - You might not write more of a unit test than is sufficient to fail, and not compiling is failing - You may not write more production code then is sufficient to pass the currently failing test
  • 8. TDD Iterations Test Production code Write minimal Unit Test Create a Class Call method of the class Create the Method Assert output of the Add logic to return method expected output
  • 9. Unit Testing "In computer programming, unit testing is a method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine if they are fit for use." - Wikipedia
  • 10. Unit Testing in English Testing smallest testable parts of application
  • 11. Unit Test is not a Test - Very narrow and well defined scope - No complex dependencies - Test only one application layer - Environment independent - Fast
  • 12. TTD - Too Damn Difficult?
  • 13. Benefits for Developer - Confidence - Code quality - Time - Refactoring - Reopening issues - Self documenting code
  • 15. Benefits for Business - Shorten development cycles - Delivering more - Stable products
  • 16. Research 1 "Art of Unit Testing" by Roy Osherove Stage Team without tests Team with tests Implementation 7 days 14 days (coding) Integration 7 days 2 days Testing / Bug Fixing 12 days 8 days Overall release time 26 days 24 days Bugs in production 71 11
  • 17. Research 2 Quality improvement through test driven development: results and experiences of four industrial teams (2008) by Nachiappan Nagappan, E. Michael Maximilien, Thirumalesh Bhat and Laurie Williams http://biblio.gdinwiddie. com/biblio/StudiesOfTestDrivenDevelopment
  • 18. Research 2 Metric IBM Drivers Microsoft: Microsoft: Microsoft: VS description Windows MSN Defect density W X Y Z of comparable team in organization but not using TDD Defect density 0.61W 0.38X 0.24Y 0.09Z of team using TDD Increase in time 15-20% 25-35% 15% 20-25% taken to code the feature because of TDD (%)
  • 19. How to test? <?php MyFramework::bootstrap(); $obj = new Class_Under_Test(); if( $obj->something('Foo') != 47 ) { throw new Exception('Incorrect output for Foo'); } if( $obj->someting('Bar') !== false ) { throw new Exception('Incorrect output for Bar'); }
  • 20. Unit Test Frameworks - PHPUnit - SimpleTest
  • 21. Using Framework - API - No maintenance - Integration with IDE - Code coverage report - Mocks
  • 22.
  • 23. <?php class MyClassTest extends PHPUnit_Framework_TestCase { public static function setUpBeforeClass() { MyFramework::initAutoloader(); } protected function setUp() { $this->myClass = new MyClass(); } public function testSomething() { $this->assertEquals(1, $this->myClass->something()); } public function testSomethingElse() { $this->assertTrue( $this->myClass->somethingElse() ); $this->assertFalse $this->myClass->somethingElse( 47 ) ); } }
  • 24. PHPUnit - Eclipse integration
  • 25. Unit Testing - small print - Can't test directly private, protected and static methods - Tests only functionality - Database - Requires rigorous discipline
  • 26. SHOULD I TRY IT? YESREFACTOR
  • 27. Q&A