SlideShare a Scribd company logo
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

More Related Content

What's hot

Test Fest 2009
Test Fest 2009Test Fest 2009
Test Fest 2009
Pierre Joye
 
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)
Ikhtiar Khan Sohan
 
Switch statement mcq
Switch statement  mcqSwitch statement  mcq
Switch statement mcq
Parthipan Parthi
 
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
Felipe Prado
 
C&cpu
C&cpuC&cpu
C&cpu
feathertw
 
[LaravelConf Taiwan 2019] 編輯器之華山論劍
[LaravelConf Taiwan 2019] 編輯器之華山論劍[LaravelConf Taiwan 2019] 編輯器之華山論劍
[LaravelConf Taiwan 2019] 編輯器之華山論劍
LaravelConfTaiwan
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
Mohammad Shaker
 
Pegomock, a mocking framework for Go
Pegomock, a mocking framework for GoPegomock, a mocking framework for Go
Pegomock, a mocking framework for Go
Peter Goetz
 
Programming basics
Programming basicsProgramming basics
Programming basics
246paa
 
Session05 iteration structure
Session05 iteration structureSession05 iteration structure
Session05 iteration structure
HarithaRanasinghe
 
Android taipei 20160225 淺談closure
Android taipei 20160225   淺談closureAndroid taipei 20160225   淺談closure
Android taipei 20160225 淺談closure
Gance Zhi-Hong Zhu (朱智鴻)
 
Super keyword
Super keywordSuper keyword
Super keyword
vishal choudhary
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++
Seok-joon Yun
 
Elixir @ Paris.rb
Elixir @ Paris.rbElixir @ Paris.rb
Elixir @ Paris.rb
Gregoire Lejeune
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
Mohammad Shaker
 
C++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+OperatorsC++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+Operators
Mohammad Shaker
 
Project in programming
Project in programmingProject in programming
Project in programming
sahashi11342091
 
The Code
The CodeThe Code
The Code
Gary Barber
 

What's hot (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
 

Similar to 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
 
PHPUnit testing to Zend_Test
PHPUnit testing to Zend_TestPHPUnit testing to Zend_Test
PHPUnit testing to Zend_Test
Michelangelo van Dam
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
Michelangelo van Dam
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
Michelangelo van Dam
 
Phpunit
PhpunitPhpunit
Phpunit
japan_works
 
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
Wim 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.5
Wim 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.5
Wim 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 PHPUnit
Edorian
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
Thanh 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.4
Wim 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 engine
Damien Seguy
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
Jagat 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 tek12
Michelangelo van Dam
 
13 PHPUnit #burningkeyboards
13 PHPUnit #burningkeyboards13 PHPUnit #burningkeyboards
13 PHPUnit #burningkeyboards
Denis 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
 

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

More from 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 - devfest
Francesco 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
 
Okr per community - icms
Okr   per community - icmsOkr   per community - icms
Okr per community - icms
Francesco Fullone
 
Open Governance, un caso reale
Open Governance, un caso realeOpen Governance, un caso reale
Open Governance, un caso reale
Francesco Fullone
 
A recommendation engine for your applications
A recommendation engine for your applicationsA recommendation engine for your applications
A recommendation engine for your applications
Francesco Fullone
 
A recommendation engine for your applications
A recommendation engine for your applicationsA recommendation engine for your applications
A recommendation engine for your applications
Francesco Fullone
 
Con te non ci lavoro
Con te non ci lavoroCon te non ci lavoro
Con te non ci lavoro
Francesco Fullone
 
Con te non ci lavoro
Con te non ci lavoroCon te non ci lavoro
Con te non ci lavoro
Francesco Fullone
 
Continuous budgeting
Continuous budgetingContinuous budgeting
Continuous budgeting
Francesco Fullone
 
Remote working istruzioni
Remote working istruzioniRemote working istruzioni
Remote working istruzioni
Francesco Fullone
 
Remote working istruzioni
Remote working istruzioniRemote working istruzioni
Remote working istruzioni
Francesco 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 Azure
Francesco Fullone
 
Remote working istruzioni
Remote working istruzioniRemote working istruzioni
Remote working istruzioni
Francesco Fullone
 
Help yourself, grow an healthy ecosystem
Help yourself, grow an healthy ecosystemHelp yourself, grow an healthy ecosystem
Help yourself, grow an healthy ecosystem
Francesco 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 development
Francesco Fullone
 
Compromises and not solution
Compromises and not solutionCompromises and not solution
Compromises and not solution
Francesco Fullone
 
PHP Goes Enterprise
PHP Goes EnterprisePHP Goes Enterprise
PHP Goes Enterprise
Francesco Fullone
 
your browser, my storage
your browser, my storageyour browser, my storage
your browser, my storage
Francesco Fullone
 

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

Recently uploaded

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 

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