SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
TDD (with FLOW3)
  Karsten Dambekalns <karsten@typo3.org>




                                           Inspiring people to
                                           share
What?
Why?
How?
        Inspiring people to
        share
Test first,
  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
Test-Driven Development with FLOW3
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 first 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

Mais conteúdo relacionado

Destaque

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
 
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
 
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
 

Destaque (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
 

Semelhante a 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
 
[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
 

Semelhante a 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, Not Windows XP
XP, Not Windows XPXP, Not Windows XP
XP, Not Windows XP
 
Xp not windows xp
Xp not windows xpXp not windows xp
Xp 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 Day Vietnam 2015] XP is 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]
 
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
 

Mais de 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
 
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
 

Mais de 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
 

Último

The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)codyslingerland1
 
20140402 - Smart house demo kit
20140402 - Smart house demo kit20140402 - Smart house demo kit
20140402 - Smart house demo kitJamie (Taka) Wang
 
The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)IES VE
 
AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024Brian Pichman
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInThousandEyes
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and businessFrancesco Corti
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1DianaGray10
 
LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0DanBrown980551
 
CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024Brian Pichman
 
Patch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updatePatch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updateadam112203
 
Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...DianaGray10
 
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfTejal81
 
Oracle Database 23c Security New Features.pptx
Oracle Database 23c Security New Features.pptxOracle Database 23c Security New Features.pptx
Oracle Database 23c Security New Features.pptxSatishbabu Gunukula
 
Where developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is goingWhere developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is goingFrancesco Corti
 
Automation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsAutomation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsDianaGray10
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptxHansamali Gamage
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applicationsnooralam814309
 
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024Alkin Tezuysal
 
My key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAIMy key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAIVijayananda Mohire
 
UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2DianaGray10
 

Último (20)

The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)
 
20140402 - Smart house demo kit
20140402 - Smart house demo kit20140402 - Smart house demo kit
20140402 - Smart house demo kit
 
The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)
 
AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and business
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1
 
LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0
 
CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024
 
Patch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updatePatch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 update
 
Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...
 
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
 
Oracle Database 23c Security New Features.pptx
Oracle Database 23c Security New Features.pptxOracle Database 23c Security New Features.pptx
Oracle Database 23c Security New Features.pptx
 
Where developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is goingWhere developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is going
 
Automation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsAutomation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projects
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applications
 
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
 
My key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAIMy key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAI
 
UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2
 

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 first, code later
  • 4. 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
  • 5. 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
  • 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
  • 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 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
  • 23. D for Development Inspiring people to share
  • 24. D for Design Inspiring people to share
  • 25. D for Design Writing tests first 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
  • 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