SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
TDD, a starting point
A PHP perspective...
Francesco Fullone, Ideato.it
ff AT ideato.it
Who am I

Francesco Fullone aka Fullo

- PHP developer since 1999
-             President
-      and Open Source Evangelist
- CEO @


- Nerd and geek
TDD ?
Test Driven
Development
Why test the code?
Developers are humans,
Humans are error-prone.
Software changes
    and grows.
We need to confirm that
 the code is working
  after any changes.
xUNIT TDD approach.
PHPUnit.de
Easy to write
Easy to read
  Isolated
Composable
An example:
The bowling kata
  (courtesy grabbed from Sebastian Bergmann)
10 frames

2 rolls to knock down the 10 pins

Score for a frame is the number of pins
knocked down

Bonus for a spare (all 10 pins knocked down in
two tries): next roll

Bonus for a strike (all 10 pins knocked down in
one try): next two rolls

Extra rolls for spare or strike in the 10th frame
<?php
require_once 'BowlingGame.php';

class BowlingGameTest extends PHPUnit_Framework_TestCase
{




}
?>
<?php
require_once 'BowlingGame.php';

class BowlingGameTest extends
PHPUnit_Framework_TestCase
{
  public function testScoreForGutterGameIs0()
  {

    }

}
<?php
require_once 'BowlingGame.php';

class BowlingGameTest extends
PHPUnit_Framework_TestCase
{
  public function testScoreForGutterGameIs0()
  {
     $game = new BowlingGame;
     for ($i = 0; $i < 20; $i++) {
          $game->roll(0);
     }

        $this->assertEquals(0, $game->score());
    }

}
fullo@teletran ~ % phpunit --skeleton-class BowlingGameTest
PHPUnit 3.4.2 by Sebastian Bergmann.
Wrote skeleton for "BowlingGame" to "BowlingGame.php".

<?php
class BowlingGame
{

    public function roll()
    {
       // Remove the following line when you
       // implement this method.

        throw new RuntimeException('Not yet implemented.');
    }

    public function score()
    {
       // Remove the following line when you
       // implement this method.

        throw new RuntimeException('Not yet implemented.');
    }
}
fullo@teletran ~ % phpunit BowlingGameTest
PHPUnit 3.4.2 by Sebastian Bergmann.

E

Time: 0 seconds

There was 1 error:

1) BowlingGameTest::testScoreForGutterGameIs0
RuntimeException: Not yet implemented.
/home/fullo/BowlingGame.php:10
/home/fullo/BowlingGameTest.php:11

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
<?php
class BowlingGame
{

     public function roll($pins)
     {

     }

     public function score()
     {
        return 0;
     }
}
?>
fullo@teletran ~ % phpunit --colors BowlingGameTest
PHPUnit 3.4.2 by Sebastian Bergmann.

.

Time: 0 seconds

OK (1 test, 1 assertion)
We have to write the
tests when the code is
        fresh.
<?php
require_once 'BowlingGame.php';

class BowlingGameTest extends PHPUnit_Framework_TestCase
{
   // …

    public function testScoreForAllOnesIs20()
    {
      $game = new BowlingGame;

        for ($i = 0; $i < 20; $i++) {
            $game->roll(1);
        }

        $this->assertEquals(20, $game->score());
    }
}
fullo@teletran ~ % phpunit –colors
BowlingGameTest
PHPUnit 3.4.2 by Sebastian Bergmann.

.F

Time: 0 seconds

There was 1 failure:

1) BowlingGameTest::testScoreForAllOnesIs20
Failed asserting that <integer:0> matches
expected value <integer:20>.
/home/fullo/BowlingGameTest.php:25

FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
<?php
class BowlingGame
{

    protected $rolls = array();

    public function roll($pins)
    {
       $this->rolls[] = $pins;
    }

    public function score()
    {
        return array_sum($this->rolls);
    }
}
<?php
require_once 'BowlingGame.php';

class BowlingGameTest extends PHPUnit_Framework_TestCase
{
   // …

    public function testScoreForOneSpareAnd3Is16()
    {
      $game = new BowlingGame;

        $game->roll(5);
        $game->roll(5);
        $game->roll(3);

        // a function to to roll X times
        $this->rollMany(17, 0);
        $this->assertEquals(16, $game->score());
    }

}
fullo@teletran ~ % phpunit –colors
BowlingGameTest
PHPUnit 3.4.2 by Sebastian Bergmann.

..F

Time: 0 seconds

There was 1 failure:

1) BowlingGameTest::testScoreForOneSpareAnd3is16
Failed asserting that <integer:13> matches
expected value <integer:16>.
/home/fullo/BowlingGameTest.php:33

FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
Tests can serve
as an executable
  specification.
fullo@teletran ~ % phpunit --testdox BowlingGameTest
PHPUnit 3.4.2 by Sebastian Bergmann.

BowlingGame
[x] Score for gutter game is 0
[ ] Score for all ones is 20
[ ] Score for one spare and 3 is 16
[ ] Score for one strike and 3 and 4 is 24
[ ] Score for perfect game is 300
Why Unit Test.
To write only clean
 and useful code.
To easily iterate in
development design.
To check for
regressions.
?
For more info see Sebastian
     Bergmann's Bowling Kata
            Workshop!

http://www.slideshare.net/sebastian
  _bergmann/quality-assurance-in-
        php-projects-2164371
Francesco Fullone
     ff AT ideato.it
    skype: ffullone




 via Quinto Bucci 205
  47023 Cesena (FC)
    info AT ideato.it
     www.ideato.it

Contenu connexe

Tendances

Tendances (20)

Ch4
Ch4Ch4
Ch4
 
Vcs8
Vcs8Vcs8
Vcs8
 
Test Fest 2009
Test Fest 2009Test Fest 2009
Test Fest 2009
 
Project proposal presentation(tic tac-toe-game)
Project proposal presentation(tic tac-toe-game)Project proposal presentation(tic tac-toe-game)
Project proposal presentation(tic tac-toe-game)
 
Switch statement mcq
Switch statement  mcqSwitch statement  mcq
Switch statement mcq
 
DEF CON 23 - COLIN O'FLYNN - dont whisper my chips
DEF CON 23 - COLIN O'FLYNN - dont whisper my chipsDEF CON 23 - COLIN O'FLYNN - dont whisper my chips
DEF CON 23 - COLIN O'FLYNN - dont whisper my chips
 
C&cpu
C&cpuC&cpu
C&cpu
 
[LaravelConf Taiwan 2019] 編輯器之華山論劍
[LaravelConf Taiwan 2019] 編輯器之華山論劍[LaravelConf Taiwan 2019] 編輯器之華山論劍
[LaravelConf Taiwan 2019] 編輯器之華山論劍
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
 
Pegomock, a mocking framework for Go
Pegomock, a mocking framework for GoPegomock, a mocking framework for Go
Pegomock, a mocking framework for Go
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
Session05 iteration structure
Session05 iteration structureSession05 iteration structure
Session05 iteration structure
 
Android taipei 20160225 淺談closure
Android taipei 20160225   淺談closureAndroid taipei 20160225   淺談closure
Android taipei 20160225 淺談closure
 
Super keyword
Super keywordSuper keyword
Super keyword
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++
 
Elixir @ Paris.rb
Elixir @ Paris.rbElixir @ Paris.rb
Elixir @ Paris.rb
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
 
C++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+OperatorsC++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+Operators
 
Project in programming
Project in programmingProject in programming
Project in programming
 
The Code
The CodeThe Code
The Code
 

En vedette

ColdFusion framework comparison
ColdFusion framework comparisonColdFusion framework comparison
ColdFusion framework comparisonVIkas Patel
 
Gabriele Lana: Testing Web Applications
Gabriele Lana: Testing Web ApplicationsGabriele Lana: Testing Web Applications
Gabriele Lana: Testing Web ApplicationsFrancesco Fullone
 
Massimiliano Wosz - Zend Framework 1.5
Massimiliano Wosz - Zend Framework 1.5Massimiliano Wosz - Zend Framework 1.5
Massimiliano Wosz - Zend Framework 1.5Francesco Fullone
 
From webagency to...a better job, life and a lot of fun
From webagency to...a better job, life and a lot of funFrom webagency to...a better job, life and a lot of fun
From webagency to...a better job, life and a lot of funFrancesco Fullone
 
Pietro Brambati: PHP e la piattaforma Microsoft
Pietro Brambati: PHP e la piattaforma MicrosoftPietro Brambati: PHP e la piattaforma Microsoft
Pietro Brambati: PHP e la piattaforma MicrosoftFrancesco Fullone
 
Gaetano Giunta: introduzione agli eZ components
Gaetano Giunta: introduzione agli eZ componentsGaetano Giunta: introduzione agli eZ components
Gaetano Giunta: introduzione agli eZ componentsFrancesco Fullone
 
Please, dont touch the slow parts v.3.6 @webtechcon
Please, dont touch the slow parts v.3.6 @webtechconPlease, dont touch the slow parts v.3.6 @webtechcon
Please, dont touch the slow parts v.3.6 @webtechconFrancesco Fullone
 

En vedette (8)

ColdFusion framework comparison
ColdFusion framework comparisonColdFusion framework comparison
ColdFusion framework comparison
 
Gabriele Lana: Testing Web Applications
Gabriele Lana: Testing Web ApplicationsGabriele Lana: Testing Web Applications
Gabriele Lana: Testing Web Applications
 
Massimiliano Wosz - Zend Framework 1.5
Massimiliano Wosz - Zend Framework 1.5Massimiliano Wosz - Zend Framework 1.5
Massimiliano Wosz - Zend Framework 1.5
 
From webagency to...a better job, life and a lot of fun
From webagency to...a better job, life and a lot of funFrom webagency to...a better job, life and a lot of fun
From webagency to...a better job, life and a lot of fun
 
Pietro Brambati: PHP e la piattaforma Microsoft
Pietro Brambati: PHP e la piattaforma MicrosoftPietro Brambati: PHP e la piattaforma Microsoft
Pietro Brambati: PHP e la piattaforma Microsoft
 
AwStats ed analisi dei logs
AwStats ed analisi dei logsAwStats ed analisi dei logs
AwStats ed analisi dei logs
 
Gaetano Giunta: introduzione agli eZ components
Gaetano Giunta: introduzione agli eZ componentsGaetano Giunta: introduzione agli eZ components
Gaetano Giunta: introduzione agli eZ components
 
Please, dont touch the slow parts v.3.6 @webtechcon
Please, dont touch the slow parts v.3.6 @webtechconPlease, dont touch the slow parts v.3.6 @webtechcon
Please, dont touch the slow parts v.3.6 @webtechcon
 

Similaire à TDD, a starting point...

New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmanndpc
 
Quality Assurance in PHP projects - Sebastian Bergmann
Quality Assurance in PHP projects - Sebastian BergmannQuality Assurance in PHP projects - Sebastian Bergmann
Quality Assurance in PHP projects - Sebastian Bergmanndpc
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitMichelangelo van Dam
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09Michelangelo van Dam
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6Wim Godden
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5Wim Godden
 
The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5Wim Godden
 
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...Rodolfo Carvalho
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnitEdorian
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnitEdorian
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentationThanh Robi
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4Wim Godden
 
Unlock The Mystery Of PHPUnit (Wave PHP 2018)
Unlock The Mystery Of PHPUnit (Wave PHP 2018)Unlock The Mystery Of PHPUnit (Wave PHP 2018)
Unlock The Mystery Of PHPUnit (Wave PHP 2018)ENDelt260
 
Exakat for PHP : smart code reviewing engine
Exakat for PHP : smart code reviewing engineExakat for PHP : smart code reviewing engine
Exakat for PHP : smart code reviewing engineDamien Seguy
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsJagat Kothari
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
13 PHPUnit #burningkeyboards
13 PHPUnit #burningkeyboards13 PHPUnit #burningkeyboards
13 PHPUnit #burningkeyboardsDenis Ristic
 
Reutov, yunusov, nagibin random numbers take ii
Reutov, yunusov, nagibin   random numbers take iiReutov, yunusov, nagibin   random numbers take ii
Reutov, yunusov, nagibin random numbers take iiDefconRussia
 

Similaire à TDD, a starting point... (20)

New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmann
 
Quality Assurance in PHP projects - Sebastian Bergmann
Quality Assurance in PHP projects - Sebastian BergmannQuality Assurance in PHP projects - Sebastian Bergmann
Quality Assurance in PHP projects - Sebastian Bergmann
 
PHPUnit testing to Zend_Test
PHPUnit testing to Zend_TestPHPUnit testing to Zend_Test
PHPUnit testing to Zend_Test
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
Phpunit
PhpunitPhpunit
Phpunit
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5
 
The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5
 
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
Unlock The Mystery Of PHPUnit (Wave PHP 2018)
Unlock The Mystery Of PHPUnit (Wave PHP 2018)Unlock The Mystery Of PHPUnit (Wave PHP 2018)
Unlock The Mystery Of PHPUnit (Wave PHP 2018)
 
Exakat for PHP : smart code reviewing engine
Exakat for PHP : smart code reviewing engineExakat for PHP : smart code reviewing engine
Exakat for PHP : smart code reviewing engine
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
13 PHPUnit #burningkeyboards
13 PHPUnit #burningkeyboards13 PHPUnit #burningkeyboards
13 PHPUnit #burningkeyboards
 
Reutov, yunusov, nagibin random numbers take ii
Reutov, yunusov, nagibin   random numbers take iiReutov, yunusov, nagibin   random numbers take ii
Reutov, yunusov, nagibin random numbers take ii
 

Plus de Francesco Fullone

Life Cycle Design e Circular Economy: un caso reale
Life Cycle Design e Circular Economy: un caso reale Life Cycle Design e Circular Economy: un caso reale
Life Cycle Design e Circular Economy: un caso reale Francesco Fullone
 
Okr istruzioni per l'uso - devfest
Okr   istruzioni per l'uso - devfestOkr   istruzioni per l'uso - devfest
Okr istruzioni per l'uso - devfestFrancesco Fullone
 
OKR, sono veramente utili alla mia azienda?
OKR, sono veramente utili alla mia azienda?OKR, sono veramente utili alla mia azienda?
OKR, sono veramente utili alla mia azienda?Francesco Fullone
 
Open Governance, un caso reale
Open Governance, un caso realeOpen Governance, un caso reale
Open Governance, un caso realeFrancesco Fullone
 
A recommendation engine for your applications
A recommendation engine for your applicationsA recommendation engine for your applications
A recommendation engine for your applicationsFrancesco Fullone
 
A recommendation engine for your applications
A recommendation engine for your applicationsA recommendation engine for your applications
A recommendation engine for your applicationsFrancesco Fullone
 
MVP & Startup, with OpenSource Software and Microsoft Azure
MVP & Startup, with OpenSource Software and Microsoft AzureMVP & Startup, with OpenSource Software and Microsoft Azure
MVP & Startup, with OpenSource Software and Microsoft AzureFrancesco Fullone
 
Help yourself, grow an healthy ecosystem
Help yourself, grow an healthy ecosystemHelp yourself, grow an healthy ecosystem
Help yourself, grow an healthy ecosystemFrancesco Fullone
 
Outsourcing, partners or suppliers?
Outsourcing, partners or suppliers?Outsourcing, partners or suppliers?
Outsourcing, partners or suppliers?Francesco Fullone
 
From brainstorming to product development
From brainstorming to product developmentFrom brainstorming to product development
From brainstorming to product developmentFrancesco Fullone
 
Compromises and not solution
Compromises and not solutionCompromises and not solution
Compromises and not solutionFrancesco Fullone
 

Plus de Francesco Fullone (20)

Life Cycle Design e Circular Economy: un caso reale
Life Cycle Design e Circular Economy: un caso reale Life Cycle Design e Circular Economy: un caso reale
Life Cycle Design e Circular Economy: un caso reale
 
Okr istruzioni per l'uso - devfest
Okr   istruzioni per l'uso - devfestOkr   istruzioni per l'uso - devfest
Okr istruzioni per l'uso - devfest
 
OKR, sono veramente utili alla mia azienda?
OKR, sono veramente utili alla mia azienda?OKR, sono veramente utili alla mia azienda?
OKR, sono veramente utili alla mia azienda?
 
Okr per community - icms
Okr   per community - icmsOkr   per community - icms
Okr per community - icms
 
Open Governance, un caso reale
Open Governance, un caso realeOpen Governance, un caso reale
Open Governance, un caso reale
 
A recommendation engine for your applications
A recommendation engine for your applicationsA recommendation engine for your applications
A recommendation engine for your applications
 
A recommendation engine for your applications
A recommendation engine for your applicationsA recommendation engine for your applications
A recommendation engine for your applications
 
Con te non ci lavoro
Con te non ci lavoroCon te non ci lavoro
Con te non ci lavoro
 
Con te non ci lavoro
Con te non ci lavoroCon te non ci lavoro
Con te non ci lavoro
 
Continuous budgeting
Continuous budgetingContinuous budgeting
Continuous budgeting
 
Remote working istruzioni
Remote working istruzioniRemote working istruzioni
Remote working istruzioni
 
Remote working istruzioni
Remote working istruzioniRemote working istruzioni
Remote working istruzioni
 
MVP & Startup, with OpenSource Software and Microsoft Azure
MVP & Startup, with OpenSource Software and Microsoft AzureMVP & Startup, with OpenSource Software and Microsoft Azure
MVP & Startup, with OpenSource Software and Microsoft Azure
 
Remote working istruzioni
Remote working istruzioniRemote working istruzioni
Remote working istruzioni
 
Help yourself, grow an healthy ecosystem
Help yourself, grow an healthy ecosystemHelp yourself, grow an healthy ecosystem
Help yourself, grow an healthy ecosystem
 
Outsourcing, partners or suppliers?
Outsourcing, partners or suppliers?Outsourcing, partners or suppliers?
Outsourcing, partners or suppliers?
 
From brainstorming to product development
From brainstorming to product developmentFrom brainstorming to product development
From brainstorming to product development
 
Compromises and not solution
Compromises and not solutionCompromises and not solution
Compromises and not solution
 
PHP Goes Enterprise
PHP Goes EnterprisePHP Goes Enterprise
PHP Goes Enterprise
 
your browser, my storage
your browser, my storageyour browser, my storage
your browser, my storage
 

Dernier

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
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.pdfsudhanshuwaghmare1
 
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...apidays
 
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 TerraformAndrey Devyatkin
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
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.pptxRemote DBA Services
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
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 FMESafe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
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...apidays
 
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​Bhuvaneswari Subramani
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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 ModelDeepika Singh
 

Dernier (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - 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...
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
+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...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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...
 
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​
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 

TDD, a starting point...

  • 1. TDD, a starting point A PHP perspective... Francesco Fullone, Ideato.it ff AT ideato.it
  • 2. Who am I Francesco Fullone aka Fullo - PHP developer since 1999 - President - and Open Source Evangelist - CEO @ - Nerd and geek
  • 5. Why test the code?
  • 6. Developers are humans, Humans are error-prone.
  • 7. Software changes and grows.
  • 8. We need to confirm that the code is working after any changes.
  • 10.
  • 12. Easy to write Easy to read Isolated Composable
  • 13. An example: The bowling kata (courtesy grabbed from Sebastian Bergmann)
  • 14. 10 frames 2 rolls to knock down the 10 pins Score for a frame is the number of pins knocked down Bonus for a spare (all 10 pins knocked down in two tries): next roll Bonus for a strike (all 10 pins knocked down in one try): next two rolls Extra rolls for spare or strike in the 10th frame
  • 15. <?php require_once 'BowlingGame.php'; class BowlingGameTest extends PHPUnit_Framework_TestCase { } ?>
  • 16. <?php require_once 'BowlingGame.php'; class BowlingGameTest extends PHPUnit_Framework_TestCase { public function testScoreForGutterGameIs0() { } }
  • 17. <?php require_once 'BowlingGame.php'; class BowlingGameTest extends PHPUnit_Framework_TestCase { public function testScoreForGutterGameIs0() { $game = new BowlingGame; for ($i = 0; $i < 20; $i++) { $game->roll(0); } $this->assertEquals(0, $game->score()); } }
  • 18. fullo@teletran ~ % phpunit --skeleton-class BowlingGameTest PHPUnit 3.4.2 by Sebastian Bergmann. Wrote skeleton for "BowlingGame" to "BowlingGame.php". <?php class BowlingGame { public function roll() { // Remove the following line when you // implement this method. throw new RuntimeException('Not yet implemented.'); } public function score() { // Remove the following line when you // implement this method. throw new RuntimeException('Not yet implemented.'); } }
  • 19. fullo@teletran ~ % phpunit BowlingGameTest PHPUnit 3.4.2 by Sebastian Bergmann. E Time: 0 seconds There was 1 error: 1) BowlingGameTest::testScoreForGutterGameIs0 RuntimeException: Not yet implemented. /home/fullo/BowlingGame.php:10 /home/fullo/BowlingGameTest.php:11 FAILURES! Tests: 1, Assertions: 0, Errors: 1.
  • 20. <?php class BowlingGame { public function roll($pins) { } public function score() { return 0; } } ?>
  • 21. fullo@teletran ~ % phpunit --colors BowlingGameTest PHPUnit 3.4.2 by Sebastian Bergmann. . Time: 0 seconds OK (1 test, 1 assertion)
  • 22. We have to write the tests when the code is fresh.
  • 23. <?php require_once 'BowlingGame.php'; class BowlingGameTest extends PHPUnit_Framework_TestCase { // … public function testScoreForAllOnesIs20() { $game = new BowlingGame; for ($i = 0; $i < 20; $i++) { $game->roll(1); } $this->assertEquals(20, $game->score()); } }
  • 24. fullo@teletran ~ % phpunit –colors BowlingGameTest PHPUnit 3.4.2 by Sebastian Bergmann. .F Time: 0 seconds There was 1 failure: 1) BowlingGameTest::testScoreForAllOnesIs20 Failed asserting that <integer:0> matches expected value <integer:20>. /home/fullo/BowlingGameTest.php:25 FAILURES! Tests: 2, Assertions: 2, Failures: 1.
  • 25. <?php class BowlingGame { protected $rolls = array(); public function roll($pins) { $this->rolls[] = $pins; } public function score() { return array_sum($this->rolls); } }
  • 26. <?php require_once 'BowlingGame.php'; class BowlingGameTest extends PHPUnit_Framework_TestCase { // … public function testScoreForOneSpareAnd3Is16() { $game = new BowlingGame; $game->roll(5); $game->roll(5); $game->roll(3); // a function to to roll X times $this->rollMany(17, 0); $this->assertEquals(16, $game->score()); } }
  • 27. fullo@teletran ~ % phpunit –colors BowlingGameTest PHPUnit 3.4.2 by Sebastian Bergmann. ..F Time: 0 seconds There was 1 failure: 1) BowlingGameTest::testScoreForOneSpareAnd3is16 Failed asserting that <integer:13> matches expected value <integer:16>. /home/fullo/BowlingGameTest.php:33 FAILURES! Tests: 2, Assertions: 2, Failures: 1.
  • 28. Tests can serve as an executable specification.
  • 29. fullo@teletran ~ % phpunit --testdox BowlingGameTest PHPUnit 3.4.2 by Sebastian Bergmann. BowlingGame [x] Score for gutter game is 0 [ ] Score for all ones is 20 [ ] Score for one spare and 3 is 16 [ ] Score for one strike and 3 and 4 is 24 [ ] Score for perfect game is 300
  • 31. To write only clean and useful code.
  • 32. To easily iterate in development design.
  • 34. ?
  • 35. For more info see Sebastian Bergmann's Bowling Kata Workshop! http://www.slideshare.net/sebastian _bergmann/quality-assurance-in- php-projects-2164371
  • 36. Francesco Fullone ff AT ideato.it skype: ffullone via Quinto Bucci 205 47023 Cesena (FC) info AT ideato.it www.ideato.it