SlideShare ist ein Scribd-Unternehmen logo
1 von 40
Downloaden Sie, um offline zu lesen
TDD (with FLOW3)
  Karsten Dambekalns <karsten@typo3.org>




                                           Inspiring people to
                                           share
What?
Why?
How?
        Inspiring people to
        share
Test rst,
  code later
TDD is about Tests
 Write tests for all your code

 •   New features come with a test

 •   Bugfixes come with a test




                                     Inspiring people to
                                     share
TDD is about Tests
 Write tests for all your code

 •   New features come with a test

 •   Bugfixes come with a test

 Write tests before your code

 •   Adding a feature means adding a test first

 •   Fixing a bug means writing a test first




                                                 Inspiring people to
                                                 share
The TDD Mantra
         Design




                  Inspiring people to
                  share
The TDD Mantra
         Design



                  Test fails




                   Inspiring people to
                  share
The TDD Mantra
         Design



                    Test fails




        Implement



                     Inspiring people to
                    share
The TDD Mantra
                 Design



  Test passes               Test fails




                Implement



                             Inspiring people to
                            share
The TDD Mantra
                 Design



  Test passes               Test fails




                Implement



                             Inspiring people to
                            share
Unit tests
  Unit tests are small programs that test your code

  They check

 •   the result of methods against expected values

 •   whether methods are (not) called as expected

  A test should

 •   be well-named

 •   check only one assertion



                                                  Inspiring people to
                                                  share
Good tests
 Should be...

 •   automated

 •   self-contained

 •   repeatable

 •   thorough

 •   small

 •   talk about the domain



                             Inspiring people to
                             share
Running unit tests
 Unit tests are usually run with a test runner

 The xUnit family is most widespread

 PHPUnit does the job for PHP

 FLOW3 has a Testing package

 •   acts as test runner

 •   provides helpful environment

 •   web-based and CLI tool



                                                 Inspiring people to
                                                 share
Running unit tests
 Unit tests are usually run with a test runner

 The xUnit family is most widespread

 PHPUnit does the job for PHP

 FLOW3 has a Testing package

 •   acts as test runner

 •   provides helpful environment

 •   web-based and CLI tool



                                                 Inspiring people to
                                                 share
Running unit tests
 Unit tests are usually run with a test runner

 The xUnit family is most widespread

 PHPUnit does the job for PHP

 FLOW3 has a Testing package

 •   acts as test runner

 •   provides helpful environment

 •   web-based and CLI tool



                                                 Inspiring people to
                                                 share
Running unit tests
 Unit tests are usually run with a test runner

 The xUnit family is most widespread

 PHPUnit does the job for PHP

 FLOW3 has a Testing package

 •   acts as test runner

 •   provides helpful environment

 •   web-based and CLI tool



                                                 Inspiring people to
                                                 share
Tests aren’t
   the goal
They make you feel good
They make you feel good
    What the tests do for you is the key

    The tests make you

•     focus on your task

•     code exactly what you need

•     think from the outside

•     a better programmer*




                                           Inspiring people to
                                           share
They make you feel good
    What the tests do for you is the key

    The tests make you

•     focus on your task

•     code exactly what you need

•     think from the outside

•     a better programmer*
                                   * decoupling helps with testing,
                                   decoupled code is easier to maintain,
                                   easier is better - q.e.d.


                                                       Inspiring people to
                                                       share
Use TDD to...
  Feel more comfortable

 •   Build confidence in your code

 •   Reduce fear of change

  Have a safety net

 •   Regression testing built in

 •   Helps with refactoring

  Provide (good) documentation through (good) tests



                                                Inspiring people to
                                                share
D for Development




                Inspiring people to
                share
D for Design




               Inspiring people to
               share
D for Design
 Writing tests rst is likely to improve your code

 •   You use the API before you code

 •   You make the API fit your needs

 Unit testing ensures decoupling

 You only code what is really needed

 Constant refactoring keeps code clean




                                                     Inspiring people to
                                                     share
TDD in Practice
  Write down your next goal

  Now write a test to check this

  The test will fail, it might even break with a fatal error

  Now write the code you need to write

  If you test again, the test should now pass

  Iterate – until it passes or all features are in




                                                      Inspiring people to
                                                     share
No FLOW3?
 No TDD!
       Inspiring people to
       share
Dependencies
 Classes explicitly refer to other classes

 But you want to test a small unit

 You don't want to test

 •   The Steamer

 •   The Grinder

 You want to test

 •   if the Barista uses the right amount of coffee and the
     requested milk when asked for coffee


                                                   Inspiring people to
                                                   share
Dependencies – bad
class Barista {

     /**
      * Makes a drink
      *
      * @param string $drink
      */
     public function make($drink) {
          if ($drink === 'Tea') {
               throw new F3::Demo::Exception::NotAvailable(
                       'We don't serve no tea, Sir', 1223385110);
          }

          $coffeeGrinder = new Grinder();
          $steamer = new Steamer();

          $coffee = $coffeeGrinder->grind(9, Grinder::FINE);
          $milk = $steamer->getSteamedMilk(Steamer::FAT_LOW);
     }
}




                                                                     Inspiring people to
                                                                     share
Dependency Injection
 This methodology is referred to as the quot;Hollywood Principlequot;:
 quot;Don't call us, we'll call youquot;

 A class doesn't ask for the instance of another class but gets it
 injected

 Enforces loose coupling and high cohesion

 Allows you to mock collaborators

 Makes you a better programmer




                                                   Inspiring people to
                                                   share
Dependencies – good
class Barista {

     /**
      * @var F3::Demo::Grinder
      */
     protected $grinder;

     /**
      * @var F3::Demo::Steamer
      */
     protected $steamer;

     /**
      *
      * @param Grinder $grinder
      * @param Steamer $steamer
      */
     public function __construct(F3::Demo::Grinder $grinder, F3::Demo::Steamer $steamer) {
          $this->grinder = $grinder;
          $this->steamer = $steamer;
     }




                                                                       Inspiring people to
                                                                       share
Dependencies – good
 /**
  * Makes a drink
  *
  * @param string $drink
  */
 public function make($drink) {
      if ($drink === 'Tea') {
           throw new F3::Demo::Exception::NotAvailable(
                       'We don't serve no tea, Sir', 1223385110);
      }

      $coffee = $this->grinder->grind(9, Grinder::FINE);
      $milk = $this->steamer->getSteamedMilk(Steamer::FAT_LOW);
 }




                                                                  Inspiring people to
                                                                  share
Without Dependency
Injection you cannot
   do unit testing

                Inspiring people to
                share
So, what to
       inject?
           Inspiring people to
           share
Mocks & Stubs
 Sometimes you need to test interaction with external systems,
 like milk steamers

 A test should be small, encapsulated, stand-alone



 Mock objects allow you to use fake objects

 Stubs can be used to return hard-coded results

 Using them is actually (somewhat) easy with PHPUnit




                                                  Inspiring people to
                                                  share
FLOW3 + TDD = FUN
 FLOW3 makes Dependency Injection easy

 With Dependency Injection you can do proper unit testing

 Proper unit tests

 •   help produce reliable code

 •   make refactoring possible

 •   make you feel better

 All this means more fun while coding



                                                Inspiring people to
                                                share
Questions!

        Inspiring people to
        share
Literature
   Test-Driven Development By Example
   Kent Beck, Addison-Wesley


   Continuous Integration – Improving Software Quality and
   Reducing Risk
   Paul M. Duvall, Addison-Wesley

   xUnit Test Patterns – Refactoring Test Code
   Gerard Meszaros, Addison-Wesley




                                                 Inspiring people to
                                                 share
Links
   FLOW3
   http://flow3.typo3.org/



   PHPUnit
   http://www.phpunit.de/



   TDD in Wikipedia
   http://en.wikipedia.org/wiki/Test-driven_development




                                            Inspiring people to
                                            share
Test-Driven Development with FLOW3

Weitere ähnliche Inhalte

Andere mochten auch

Semantic TYPO3
Semantic TYPO3Semantic TYPO3
Semantic TYPO3Jochen Rau
 
Feb 2012 sustainability mls
Feb 2012 sustainability  mlsFeb 2012 sustainability  mls
Feb 2012 sustainability mlsHack the Hood
 
Designstudionotes
DesignstudionotesDesignstudionotes
DesignstudionotesWilliam Wilkie
 
أنشطة مصلحة النظافة
أنشطة مصلحة النظافةأنشطة مصلحة النظافة
أنشطة مصلحة النظافةMohamed Larbi BEN YOUNES
 
Open Government and local community foundations: Getting involved
Open Government and local community foundations: Getting involvedOpen Government and local community foundations: Getting involved
Open Government and local community foundations: Getting involvedHack the Hood
 
1.1 My Works About Proposal / Presentation
1.1 My Works About Proposal / Presentation1.1 My Works About Proposal / Presentation
1.1 My Works About Proposal / PresentationRuby Kuo
 
i18n and L10n in TYPO3 Flow
i18n and L10n in TYPO3 Flowi18n and L10n in TYPO3 Flow
i18n and L10n in TYPO3 FlowKarsten Dambekalns
 
7 Habits of SEO-Centric Web Design
7 Habits of SEO-Centric Web Design7 Habits of SEO-Centric Web Design
7 Habits of SEO-Centric Web DesignDino Baskovic
 
How to start an online business:7 stories of success
How to start an online business:7 stories of successHow to start an online business:7 stories of success
How to start an online business:7 stories of successE-Web Marketing
 
Project execution for paranoids
Project execution for paranoidsProject execution for paranoids
Project execution for paranoidsHack the Hood
 
Cross-border learning with eTwinning
Cross-border learning with   eTwinningCross-border learning with   eTwinning
Cross-border learning with eTwinningRositsa Dimova
 
Endangered species in spain map
Endangered species in spain mapEndangered species in spain map
Endangered species in spain mapRositsa Dimova
 
Do italia sas samolet
Do italia sas samoletDo italia sas samolet
Do italia sas samoletRositsa Dimova
 
Natural attractions
Natural attractionsNatural attractions
Natural attractionsRositsa Dimova
 

Andere mochten auch (17)

Semantic TYPO3
Semantic TYPO3Semantic TYPO3
Semantic TYPO3
 
Feb 2012 sustainability mls
Feb 2012 sustainability  mlsFeb 2012 sustainability  mls
Feb 2012 sustainability mls
 
Designstudionotes
DesignstudionotesDesignstudionotes
Designstudionotes
 
أنشطة مصلحة النظافة
أنشطة مصلحة النظافةأنشطة مصلحة النظافة
أنشطة مصلحة النظافة
 
Open Government and local community foundations: Getting involved
Open Government and local community foundations: Getting involvedOpen Government and local community foundations: Getting involved
Open Government and local community foundations: Getting involved
 
Aaa
AaaAaa
Aaa
 
1.1 My Works About Proposal / Presentation
1.1 My Works About Proposal / Presentation1.1 My Works About Proposal / Presentation
1.1 My Works About Proposal / Presentation
 
i18n and L10n in TYPO3 Flow
i18n and L10n in TYPO3 Flowi18n and L10n in TYPO3 Flow
i18n and L10n in TYPO3 Flow
 
7 Habits of SEO-Centric Web Design
7 Habits of SEO-Centric Web Design7 Habits of SEO-Centric Web Design
7 Habits of SEO-Centric Web Design
 
How to start an online business:7 stories of success
How to start an online business:7 stories of successHow to start an online business:7 stories of success
How to start an online business:7 stories of success
 
Project execution for paranoids
Project execution for paranoidsProject execution for paranoids
Project execution for paranoids
 
ANT
ANTANT
ANT
 
Cross-border learning with eTwinning
Cross-border learning with   eTwinningCross-border learning with   eTwinning
Cross-border learning with eTwinning
 
Endangered species in spain map
Endangered species in spain mapEndangered species in spain map
Endangered species in spain map
 
Do italia sas samolet
Do italia sas samoletDo italia sas samolet
Do italia sas samolet
 
Simone project
Simone projectSimone project
Simone project
 
Natural attractions
Natural attractionsNatural attractions
Natural attractions
 

Ähnlich wie Test-Driven Development with FLOW3

Beyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver SoftwareBeyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver SoftwareChris Weldon
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development CodeOps Technologies LLP
 
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 downDaniel Irvine
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Danny Preussler
 
TDD Workshop (January, 2018)
TDD Workshop (January, 2018)TDD Workshop (January, 2018)
TDD Workshop (January, 2018)Rachel M. Carmena
 
Pair Programming Presentation
Pair Programming PresentationPair Programming Presentation
Pair Programming PresentationThoughtWorks
 
XP, Not Windows XP
XP, Not Windows XPXP, Not Windows XP
XP, Not Windows XPAlexandre Cuva
 
[XPday.vn] XP? not Windows XP {presentation} (at) [XP Day Vietnam 2015]
[XPday.vn] XP? not Windows XP {presentation} (at) [XP Day Vietnam 2015][XPday.vn] XP? not Windows XP {presentation} (at) [XP Day Vietnam 2015]
[XPday.vn] XP? not Windows XP {presentation} (at) [XP Day Vietnam 2015]Agile đây Vietnam
 
How penetration testing techniques can help you improve your qa skills
How penetration testing techniques can help you improve your qa skillsHow penetration testing techniques can help you improve your qa skills
How penetration testing techniques can help you improve your qa skillsMarian Marinov
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionDionatan default
 
Unit testing
Unit testingUnit testing
Unit testingPiXeL16
 
Deployment is the new build
Deployment is the new buildDeployment is the new build
Deployment is the new buildAndrew Phillips
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional ProgrammerDave Cross
 
Adopting A Whole Team Approach To Quality
Adopting  A  Whole  Team  Approach  To  QualityAdopting  A  Whole  Team  Approach  To  Quality
Adopting A Whole Team Approach To QualityBen Carey
 
Quality of Bug Reports in Open Source
Quality of Bug Reports in Open SourceQuality of Bug Reports in Open Source
Quality of Bug Reports in Open SourceThomas Zimmermann
 
David Nuescheler: Igniting CQ 5.3: What's New and Roadmap
David Nuescheler: Igniting CQ 5.3: What's New and RoadmapDavid Nuescheler: Igniting CQ 5.3: What's New and Roadmap
David Nuescheler: Igniting CQ 5.3: What's New and RoadmapDay Software
 
It's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecGiulio De Donato
 

Ähnlich wie Test-Driven Development with FLOW3 (20)

TDD (with FLOW3)
TDD (with FLOW3)TDD (with FLOW3)
TDD (with FLOW3)
 
Beyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver SoftwareBeyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver Software
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
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
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
TDD Workshop (January, 2018)
TDD Workshop (January, 2018)TDD Workshop (January, 2018)
TDD Workshop (January, 2018)
 
Pair Programming Presentation
Pair Programming PresentationPair Programming Presentation
Pair Programming Presentation
 
[XP Day Vietnam 2015] XP is not windows XP
[XP Day Vietnam 2015] XP is not windows XP[XP Day Vietnam 2015] XP is not windows XP
[XP Day Vietnam 2015] XP is not windows XP
 
XP, Not Windows XP
XP, Not Windows XPXP, Not Windows XP
XP, Not Windows XP
 
[XPday.vn] XP? not Windows XP {presentation} (at) [XP Day Vietnam 2015]
[XPday.vn] XP? not Windows XP {presentation} (at) [XP Day Vietnam 2015][XPday.vn] XP? not Windows XP {presentation} (at) [XP Day Vietnam 2015]
[XPday.vn] XP? not Windows XP {presentation} (at) [XP Day Vietnam 2015]
 
Xp not windows xp
Xp not windows xpXp not windows xp
Xp not windows xp
 
How penetration testing techniques can help you improve your qa skills
How penetration testing techniques can help you improve your qa skillsHow penetration testing techniques can help you improve your qa skills
How penetration testing techniques can help you improve your qa skills
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
Unit testing
Unit testingUnit testing
Unit testing
 
Deployment is the new build
Deployment is the new buildDeployment is the new build
Deployment is the new build
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 
Adopting A Whole Team Approach To Quality
Adopting  A  Whole  Team  Approach  To  QualityAdopting  A  Whole  Team  Approach  To  Quality
Adopting A Whole Team Approach To Quality
 
Quality of Bug Reports in Open Source
Quality of Bug Reports in Open SourceQuality of Bug Reports in Open Source
Quality of Bug Reports in Open Source
 
David Nuescheler: Igniting CQ 5.3: What's New and Roadmap
David Nuescheler: Igniting CQ 5.3: What's New and RoadmapDavid Nuescheler: Igniting CQ 5.3: What's New and Roadmap
David Nuescheler: Igniting CQ 5.3: What's New and Roadmap
 
It's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspec
 

Mehr von Karsten Dambekalns

The Perfect Neos Project Setup
The Perfect Neos Project SetupThe Perfect Neos Project Setup
The Perfect Neos Project SetupKarsten Dambekalns
 
Sawubona! Content Dimensions with Neos
Sawubona! Content Dimensions with NeosSawubona! Content Dimensions with Neos
Sawubona! Content Dimensions with NeosKarsten Dambekalns
 
Deploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using SurfDeploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using SurfKarsten Dambekalns
 
Profiling TYPO3 Flow Applications
Profiling TYPO3 Flow ApplicationsProfiling TYPO3 Flow Applications
Profiling TYPO3 Flow ApplicationsKarsten Dambekalns
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowKarsten Dambekalns
 
How Git and Gerrit make you more productive
How Git and Gerrit make you more productiveHow Git and Gerrit make you more productive
How Git and Gerrit make you more productiveKarsten Dambekalns
 
The agile future of a ponderous project
The agile future of a ponderous projectThe agile future of a ponderous project
The agile future of a ponderous projectKarsten Dambekalns
 
How Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the futureHow Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the futureKarsten Dambekalns
 
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 PhoenixContent Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 PhoenixKarsten Dambekalns
 
Transparent Object Persistence (within FLOW3)
Transparent Object Persistence (within FLOW3)Transparent Object Persistence (within FLOW3)
Transparent Object Persistence (within FLOW3)Karsten Dambekalns
 
JavaScript for PHP Developers
JavaScript for PHP DevelopersJavaScript for PHP Developers
JavaScript for PHP DevelopersKarsten Dambekalns
 
Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Karsten Dambekalns
 
Implementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPImplementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPKarsten Dambekalns
 
Knowledge Management in der TYPO3 Community
Knowledge Management in der TYPO3 CommunityKnowledge Management in der TYPO3 Community
Knowledge Management in der TYPO3 CommunityKarsten Dambekalns
 
Implementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPImplementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPKarsten Dambekalns
 
A Content Repository for TYPO3 5.0
A Content Repository for TYPO3 5.0A Content Repository for TYPO3 5.0
A Content Repository for TYPO3 5.0Karsten Dambekalns
 
Introduction to Source Code Management
Introduction to Source Code ManagementIntroduction to Source Code Management
Introduction to Source Code ManagementKarsten Dambekalns
 

Mehr von Karsten Dambekalns (20)

The Perfect Neos Project Setup
The Perfect Neos Project SetupThe Perfect Neos Project Setup
The Perfect Neos Project Setup
 
Sawubona! Content Dimensions with Neos
Sawubona! Content Dimensions with NeosSawubona! Content Dimensions with Neos
Sawubona! Content Dimensions with Neos
 
Deploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using SurfDeploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using Surf
 
Profiling TYPO3 Flow Applications
Profiling TYPO3 Flow ApplicationsProfiling TYPO3 Flow Applications
Profiling TYPO3 Flow Applications
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
 
FLOW3-Workshop F3X12
FLOW3-Workshop F3X12FLOW3-Workshop F3X12
FLOW3-Workshop F3X12
 
Doctrine in FLOW3
Doctrine in FLOW3Doctrine in FLOW3
Doctrine in FLOW3
 
How Git and Gerrit make you more productive
How Git and Gerrit make you more productiveHow Git and Gerrit make you more productive
How Git and Gerrit make you more productive
 
The agile future of a ponderous project
The agile future of a ponderous projectThe agile future of a ponderous project
The agile future of a ponderous project
 
How Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the futureHow Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the future
 
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 PhoenixContent Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
 
Transparent Object Persistence (within FLOW3)
Transparent Object Persistence (within FLOW3)Transparent Object Persistence (within FLOW3)
Transparent Object Persistence (within FLOW3)
 
JavaScript for PHP Developers
JavaScript for PHP DevelopersJavaScript for PHP Developers
JavaScript for PHP Developers
 
Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3
 
Implementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPImplementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHP
 
Knowledge Management in der TYPO3 Community
Knowledge Management in der TYPO3 CommunityKnowledge Management in der TYPO3 Community
Knowledge Management in der TYPO3 Community
 
Unicode & PHP6
Unicode & PHP6Unicode & PHP6
Unicode & PHP6
 
Implementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPImplementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHP
 
A Content Repository for TYPO3 5.0
A Content Repository for TYPO3 5.0A Content Repository for TYPO3 5.0
A Content Repository for TYPO3 5.0
 
Introduction to Source Code Management
Introduction to Source Code ManagementIntroduction to Source Code Management
Introduction to Source Code Management
 

KĂźrzlich hochgeladen

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

KĂźrzlich hochgeladen (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Test-Driven Development with FLOW3

  • 1. TDD (with FLOW3) Karsten Dambekalns <karsten@typo3.org> Inspiring people to share
  • 2. What? Why? How? Inspiring people to share
  • 3. Test rst, code later
  • 4. TDD is about Tests Write tests for all your code • New features come with a test • Bugxes come with a test Inspiring people to share
  • 5. TDD is about Tests Write tests for all your code • New features come with a test • Bugxes come with a test Write tests before your code • Adding a feature means adding a test rst • Fixing a bug means writing a test rst Inspiring people to share
  • 6. The TDD Mantra Design Inspiring people to share
  • 7. The TDD Mantra Design Test fails Inspiring people to share
  • 8. The TDD Mantra Design Test fails Implement Inspiring people to share
  • 9. The TDD Mantra Design Test passes Test fails Implement Inspiring people to share
  • 10. The TDD Mantra Design Test passes Test fails Implement Inspiring people to share
  • 11. Unit tests Unit tests are small programs that test your code They check • the result of methods against expected values • whether methods are (not) called as expected A test should • be well-named • check only one assertion Inspiring people to share
  • 12. Good tests Should be... • automated • self-contained • repeatable • thorough • small • talk about the domain Inspiring people to share
  • 13. Running unit tests Unit tests are usually run with a test runner The xUnit family is most widespread PHPUnit does the job for PHP FLOW3 has a Testing package • acts as test runner • provides helpful environment • web-based and CLI tool Inspiring people to share
  • 14. Running unit tests Unit tests are usually run with a test runner The xUnit family is most widespread PHPUnit does the job for PHP FLOW3 has a Testing package • acts as test runner • provides helpful environment • web-based and CLI tool Inspiring people to share
  • 15. Running unit tests Unit tests are usually run with a test runner The xUnit family is most widespread PHPUnit does the job for PHP FLOW3 has a Testing package • acts as test runner • provides helpful environment • web-based and CLI tool Inspiring people to share
  • 16. Running unit tests Unit tests are usually run with a test runner The xUnit family is most widespread PHPUnit does the job for PHP FLOW3 has a Testing package • acts as test runner • provides helpful environment • web-based and CLI tool Inspiring people to share
  • 17. Tests aren’t the goal
  • 18.
  • 19. They make you feel good
  • 20. They make you feel good What the tests do for you is the key The tests make you • focus on your task • code exactly what you need • think from the outside • a better programmer* Inspiring people to share
  • 21. They make you feel good What the tests do for you is the key The tests make you • focus on your task • code exactly what you need • think from the outside • a better programmer* * decoupling helps with testing, decoupled code is easier to maintain, easier is better - q.e.d. Inspiring people to share
  • 22. Use TDD to... Feel more comfortable • Build condence in your code • Reduce fear of change Have a safety net • Regression testing built in • Helps with refactoring Provide (good) documentation through (good) tests Inspiring people to share
  • 23. D for Development Inspiring people to share
  • 24. D for Design Inspiring people to share
  • 25. D for Design Writing tests rst is likely to improve your code • You use the API before you code • You make the API t your needs Unit testing ensures decoupling You only code what is really needed Constant refactoring keeps code clean Inspiring people to share
  • 26. TDD in Practice Write down your next goal Now write a test to check this The test will fail, it might even break with a fatal error Now write the code you need to write If you test again, the test should now pass Iterate – until it passes or all features are in Inspiring people to share
  • 27. No FLOW3? No TDD! Inspiring people to share
  • 28. Dependencies Classes explicitly refer to other classes But you want to test a small unit You don't want to test • The Steamer • The Grinder You want to test • if the Barista uses the right amount of coffee and the requested milk when asked for coffee Inspiring people to share
  • 29. Dependencies – bad class Barista { /** * Makes a drink * * @param string $drink */ public function make($drink) { if ($drink === 'Tea') { throw new F3::Demo::Exception::NotAvailable( 'We don't serve no tea, Sir', 1223385110); } $coffeeGrinder = new Grinder(); $steamer = new Steamer(); $coffee = $coffeeGrinder->grind(9, Grinder::FINE); $milk = $steamer->getSteamedMilk(Steamer::FAT_LOW); } } Inspiring people to share
  • 30. Dependency Injection This methodology is referred to as the quot;Hollywood Principlequot;: quot;Don't call us, we'll call youquot; A class doesn't ask for the instance of another class but gets it injected Enforces loose coupling and high cohesion Allows you to mock collaborators Makes you a better programmer Inspiring people to share
  • 31. Dependencies – good class Barista { /** * @var F3::Demo::Grinder */ protected $grinder; /** * @var F3::Demo::Steamer */ protected $steamer; /** * * @param Grinder $grinder * @param Steamer $steamer */ public function __construct(F3::Demo::Grinder $grinder, F3::Demo::Steamer $steamer) { $this->grinder = $grinder; $this->steamer = $steamer; } Inspiring people to share
  • 32. Dependencies – good /** * Makes a drink * * @param string $drink */ public function make($drink) { if ($drink === 'Tea') { throw new F3::Demo::Exception::NotAvailable( 'We don't serve no tea, Sir', 1223385110); } $coffee = $this->grinder->grind(9, Grinder::FINE); $milk = $this->steamer->getSteamedMilk(Steamer::FAT_LOW); } Inspiring people to share
  • 33. Without Dependency Injection you cannot do unit testing Inspiring people to share
  • 34. So, what to inject? Inspiring people to share
  • 35. Mocks & Stubs Sometimes you need to test interaction with external systems, like milk steamers A test should be small, encapsulated, stand-alone Mock objects allow you to use fake objects Stubs can be used to return hard-coded results Using them is actually (somewhat) easy with PHPUnit Inspiring people to share
  • 36. FLOW3 + TDD = FUN FLOW3 makes Dependency Injection easy With Dependency Injection you can do proper unit testing Proper unit tests • help produce reliable code • make refactoring possible • make you feel better All this means more fun while coding Inspiring people to share
  • 37. Questions! Inspiring people to share
  • 38. Literature Test-Driven Development By Example Kent Beck, Addison-Wesley Continuous Integration – Improving Software Quality and Reducing Risk Paul M. Duvall, Addison-Wesley xUnit Test Patterns – Refactoring Test Code Gerard Meszaros, Addison-Wesley Inspiring people to share
  • 39. Links FLOW3 http://flow3.typo3.org/ PHPUnit http://www.phpunit.de/ TDD in Wikipedia http://en.wikipedia.org/wiki/Test-driven_development Inspiring people to share