SlideShare a Scribd company logo
1 of 35
Download to read offline
Rodolfo Carvalho - @201
   YAPC::Brasil 2011
Rodolfo Carvalho
● Eng. Computação UFRJ
● PythOnRio
● Coding Dojo Rio
● Ex-Globo.com, ex-Intelie
● Entusiasta de Racket
● Monge Perl?
  Quem sabe em breve :P
CPAN: Comprehensive Perl Archive Network
                metacpan.org
Desenvolvimento "tradicional"


  Design


               Code


                            Test
TDD: Test-Driven Development

     Design              Test




               Test


     Refacto
        r                Code
No longo prazo...




              x


                    ...
 tempo
Em Perl
● CPAN contém diversas opções
● TAP: "Test Anything Protocol"
Test::Simple
Test::More + Test::Exception
             Test::Differences
             Test::Deep           + prove
             Test::Warn
          = Test::Most
Exemplo
Problema: calcular o n-ésimo número da
sequência de Fibonacci.

Design: escrever uma função que recebe um
argumento numérico (n) e retorna o número da
sequência correspondente.
Exemplo: Fibonacci
Teste:                   Resultado:
use Test::More;          $ prove fibonacci.pl
                         fibonacci.pl .. Undefined
                         subroutine &main::fibonacci
is( fibonacci(0), 0 );   called at fibonacci.pl line 4.
                         fibonacci.pl .. Dubious, test
                         returned 9 (wstat 2304,
done_testing();          0x900)
Exemplo: Fibonacci
Implementação:    Resultado:
sub fibonacci {   $ prove fibonacci.pl
                  fibonacci.pl .. ok
  return 0;
                  All tests successful.
}
Exemplo: Fibonacci




               ...
Exemplo: Fibonacci
Teste:                   Implementação:
is( fibonacci(0), 0 );   sub fibonacci {
                           my $n = shift;
is( fibonacci(1), 1 );
                           return 0 if $n eq 0;
is( fibonacci(2), 1 );     return 1 if $n eq 1;
                           return 1 if $n eq 2;
                         }
Exemplo: Fibonacci
Teste:                   Resultado:
is( fibonacci(0), 0 );   $ prove fibonacci.pl
                         fibonacci.pl .. 1/?
is( fibonacci(1), 1 );
                         # Failed test at fibonacci.pl
is( fibonacci(2), 1 );   line 15.
is( fibonacci(3), 2 );   #        got: ''
                         # expected: '2'
                         # Looks like you failed 1
                         test of 4.
Exemplo: Fibonacci
Implementação:                Resultado:
sub fibonacci {               $ prove fibonacci.pl
   my $n = shift;             fibonacci.pl .. ok
   return 0 if $n eq 0;       All tests successful.
   return 1 if $n eq 1;
   return fibonacci($n-2) +
           fibonacci($n-1);
}
Exemplo: Fibonacci
Teste:                         Resultado:
my $phi = (1+sqrt 5)/2;        $ prove fibonacci.pl
my $psi = -1/$phi;             fibonacci.pl .. ok
foreach ( 0..20 ) {            All tests successful.
  is( fibonacci($_),
      ($phi**$_ - $psi**$_)/
       sqrt 5 );
}
Perl
oferece muito mais
package Example::Test;
                     use base qw(Test::Class);
                     use Test::More;

OOP's "xUnit"        # setup methods are run before every test method.
                     sub make_fixture : Test(setup) {
                        my $array = [1, 2];
                        shift->{test_array} = $array;

● Test::Class        };

                     # a test method that runs 1 test
                     sub test_push : Test {
                        my $array = shift->{test_array};
                        push @$array, 3;
                        is_deeply($array, [1, 2, 3], 'push worked');
                     };
● Test::MockObject   # a test method that runs 4 tests
                     sub test_pop : Test(4) {
                        my $array = shift->{test_array};
● DBD::Mock             is(pop @$array, 2, 'pop = 2');
                        is(pop @$array, 1, 'pop = 1');
                        is_deeply($array, [], 'array empty');
                        is(pop @$array, undef, 'pop = undef');
● Test::TCP          };

                     # teardown methods are run after every test method.
                     sub teardown : Test(teardown) {
                        my $array = shift->{test_array};
                        diag("array = (@$array) after test(s)");
                     };
TDD + Web
● Test::WWW::Mechanize


       use Test::More tests => 5;
       use Test::WWW::Mechanize;

       my $mech = Test::WWW::Mechanize->new;
       $mech->get_ok( $page );
       $mech->base_is( 'http://petdance.com/', 'Proper <BASE HREF>' );
       $mech->title_is( 'Invoice Status', "Make sure we're on the invoice page" );
       $mech->text_contains( 'Andy Lester', 'My name somewhere' );
       $mech->content_like( qr/(cpan|perl).org/, 'Link to perl.org or CPAN' );
TDD + Web
                    use Test::More tests => 10;

● Test::Mojo        use Test::Mojo;

                    my $t = Test::Mojo->new('MyApp');

                    $t->get_ok('/welcome')
                     ->status_is(200)

HTML5                ->content_like(qr/Hello!/, 'welcome message');

                    $t->post_form_ok('/search', {title => 'Perl', author => 'taro'})
                     ->status_is(200)
                     ->content_like(qr/Perl.+taro/);

Real-time webapps   $t->delete_ok('/something')
                     ->status_is(200)
                     ->header_is('X-Powered-By' => 'Mojolicious (Perl)')
                     ->header_isnt('X-Bender' => 'Bite my shiny metal ass!');
                     ->content_is('Hello world!');

                    $t->websocket_ok('/echo')
                     ->send_message_ok('hello')
                     ->message_is('echo: hello')
                     ->finish_ok;
Test anything...
● Test::Pod::Coverage
● Test::UseAllModules
● Test::NoWarnings
● Test::Perl::Critic
● Test::AskAnExpert
● Test::Inline
● Test::UniqueTestNames
Não basta escrever testes
Fácil:
● Dada uma entrada, comparar saída e saída esperada


Difícil:
● O que testar
● Como testar
● Erros não previstos
Não basta escrever testes
Short list of ways tests could fail without any code change:
 ●   "Temporary" test files and fixtures might be dirty.

 ●   "Temporary" databases and tables might be dirty.

 ●   It is sensitive to time or date.

 ●   It uses network resources and they changed.

 ●   The compiler was changed.

 ●   The installed libraries used were changed.

 ●   The libraries the libraries use were changed.

 ●   The kernel was changed.

 ●   Any servers used (databases, web servers, etc...) were changed.

 ●   It uses parallel processing and a subtle bug only occurs sometimes.

 ●   The disk (or the filesystem where temp files go) is full.

 ●   The disk (or the filesystem where temp files go) is broken.

 ●   Your memory/disk/process/filehandle quotas were reduced.

 ●   The machine has run out of memory.

 ●   The machine has run out of filehandles.

 ●   It uses fixtures with randomly generated data and generated some that tickled a bug.



                                                                                            Michael Schwern
metacpan.org
Quero fazer TDD, e agora?
Coding Dojo
Coding Dojo
● Prática deliberada de TDD
● Programação em par
● Aprendizado coletivo



                              + é divertido!
Como funciona?
     Precisamos de:
● Piloto e co-piloto
● Problema
● Computador
● Projetor
● Cronômetro
● Comida!
5 ~ 7 min
Retrospectiva
Onde




 TDD
  +
 Perl
        Centro, toda quarta-feira às 18:30
                                             UFF - Niterói
         Av Treze de Maio, 13 – sala 616     quintas 19:00
                Edifício Municipal
Agradecimentos
   Breno (Garu)              Dojo Rio




                            dojorio.org




Contato           about.me/rhcarvalho

More Related Content

What's hot

Advanced Python, Part 1
Advanced Python, Part 1Advanced Python, Part 1
Advanced Python, Part 1Zaar Hai
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentationThanh Robi
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnitvaruntaliyan
 
Software Testing
Software TestingSoftware Testing
Software TestingLambert Lum
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best PracticesEdorian
 
Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33Max Kleiner
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumlercorehard_by
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpen Gurukul
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, PloneQuintagroup
 
Php through the eyes of a hoster pbc10
Php through the eyes of a hoster pbc10Php through the eyes of a hoster pbc10
Php through the eyes of a hoster pbc10Combell NV
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?FITC
 
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityPHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityGiorgio Sironi
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Nikita Popov
 
A closure ekon16
A closure ekon16A closure ekon16
A closure ekon16Max Kleiner
 
Антон Бикинеев, Reflection in C++Next
Антон Бикинеев,  Reflection in C++NextАнтон Бикинеев,  Reflection in C++Next
Антон Бикинеев, Reflection in C++NextSergey Platonov
 
Php 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparisonPhp 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparisonTu Pham
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Guillaume Laforge
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Ismar Silveira
 

What's hot (20)

Advanced Python, Part 1
Advanced Python, Part 1Advanced Python, Part 1
Advanced Python, Part 1
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
 
Ggug spock
Ggug spockGgug spock
Ggug spock
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best Practices
 
Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
 
Php through the eyes of a hoster pbc10
Php through the eyes of a hoster pbc10Php through the eyes of a hoster pbc10
Php through the eyes of a hoster pbc10
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityPHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
A closure ekon16
A closure ekon16A closure ekon16
A closure ekon16
 
Антон Бикинеев, Reflection in C++Next
Антон Бикинеев,  Reflection in C++NextАнтон Бикинеев,  Reflection in C++Next
Антон Бикинеев, Reflection in C++Next
 
Php 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparisonPhp 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparison
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 

Viewers also liked

Intro Dojo Rio Python Campus
Intro Dojo Rio Python CampusIntro Dojo Rio Python Campus
Intro Dojo Rio Python CampusRodolfo Carvalho
 
Desenvolvimento Web com TurboGears e DOSVOX
Desenvolvimento Web com TurboGears e DOSVOXDesenvolvimento Web com TurboGears e DOSVOX
Desenvolvimento Web com TurboGears e DOSVOXRodolfo Carvalho
 
Python deployments on OpenShift 3
Python deployments on OpenShift 3Python deployments on OpenShift 3
Python deployments on OpenShift 3Rodolfo Carvalho
 
Building and Deploying containerized Python Apps in the Cloud
Building and Deploying containerized Python Apps in the CloudBuilding and Deploying containerized Python Apps in the Cloud
Building and Deploying containerized Python Apps in the CloudRodolfo Carvalho
 
Composing WSGI apps and spellchecking it all
Composing WSGI apps and spellchecking it allComposing WSGI apps and spellchecking it all
Composing WSGI apps and spellchecking it allRodolfo Carvalho
 
The Go features I can't live without
The Go features I can't live withoutThe Go features I can't live without
The Go features I can't live withoutRodolfo Carvalho
 
The Go features I can't live without, 2nd round
The Go features I can't live without, 2nd roundThe Go features I can't live without, 2nd round
The Go features I can't live without, 2nd roundRodolfo Carvalho
 

Viewers also liked (19)

Pyndorama
PyndoramaPyndorama
Pyndorama
 
Redes livres de escala
Redes livres de escalaRedes livres de escala
Redes livres de escala
 
Content Delivery Networks
Content Delivery NetworksContent Delivery Networks
Content Delivery Networks
 
Pyndorama
PyndoramaPyndorama
Pyndorama
 
Intro Dojo Rio Python Campus
Intro Dojo Rio Python CampusIntro Dojo Rio Python Campus
Intro Dojo Rio Python Campus
 
TDD do seu jeito
TDD do seu jeitoTDD do seu jeito
TDD do seu jeito
 
Redes livres de escala
Redes livres de escalaRedes livres de escala
Redes livres de escala
 
Comunicação
ComunicaçãoComunicação
Comunicação
 
Intro Dojo Rio
Intro Dojo RioIntro Dojo Rio
Intro Dojo Rio
 
Coding Kwoon
Coding KwoonCoding Kwoon
Coding Kwoon
 
Desenvolvimento Web com TurboGears e DOSVOX
Desenvolvimento Web com TurboGears e DOSVOXDesenvolvimento Web com TurboGears e DOSVOX
Desenvolvimento Web com TurboGears e DOSVOX
 
Python deployments on OpenShift 3
Python deployments on OpenShift 3Python deployments on OpenShift 3
Python deployments on OpenShift 3
 
Building and Deploying containerized Python Apps in the Cloud
Building and Deploying containerized Python Apps in the CloudBuilding and Deploying containerized Python Apps in the Cloud
Building and Deploying containerized Python Apps in the Cloud
 
Concurrency in Python4k
Concurrency in Python4kConcurrency in Python4k
Concurrency in Python4k
 
Python in 15 minutes
Python in 15 minutesPython in 15 minutes
Python in 15 minutes
 
Composing WSGI apps and spellchecking it all
Composing WSGI apps and spellchecking it allComposing WSGI apps and spellchecking it all
Composing WSGI apps and spellchecking it all
 
Pykonik Coding Dojo
Pykonik Coding DojoPykonik Coding Dojo
Pykonik Coding Dojo
 
The Go features I can't live without
The Go features I can't live withoutThe Go features I can't live without
The Go features I can't live without
 
The Go features I can't live without, 2nd round
The Go features I can't live without, 2nd roundThe Go features I can't live without, 2nd round
The Go features I can't live without, 2nd round
 

Similar to Rodolfo Carvalho - TDD and Perl Best Practices

Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023Mark Niebergall
 
Unit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentUnit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentMark Niebergall
 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.Workhorse Computing
 
Testing Code and Assuring Quality
Testing Code and Assuring QualityTesting Code and Assuring Quality
Testing Code and Assuring QualityKent Cowgill
 
Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Mark Niebergall
 
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
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdfHans Jones
 
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
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentSheeju Alex
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2Yi-Huan Chan
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityGeorgePeterBanyard
 
Django’s nasal passage
Django’s nasal passageDjango’s nasal passage
Django’s nasal passageErik Rose
 
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
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everythingnoelrap
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormMichelangelo van Dam
 
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
 

Similar to Rodolfo Carvalho - TDD and Perl Best Practices (20)

Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023
 
Unit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentUnit Testing from Setup to Deployment
Unit Testing from Setup to Deployment
 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.
 
Testing Code and Assuring Quality
Testing Code and Assuring QualityTesting Code and Assuring Quality
Testing Code and Assuring Quality
 
Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
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
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
PHPUnit testing to Zend_Test
PHPUnit testing to Zend_TestPHPUnit testing to Zend_Test
PHPUnit testing to Zend_Test
 
Dutch PHP Conference 2013: Distilled
Dutch PHP Conference 2013: DistilledDutch PHP Conference 2013: Distilled
Dutch PHP Conference 2013: Distilled
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 
Django’s nasal passage
Django’s nasal passageDjango’s nasal passage
Django’s nasal passage
 
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
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStorm
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 

More from Rodolfo Carvalho

Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoRodolfo Carvalho
 
OpenShift Overview - Red Hat Open School 2017
OpenShift Overview - Red Hat Open School 2017OpenShift Overview - Red Hat Open School 2017
OpenShift Overview - Red Hat Open School 2017Rodolfo Carvalho
 
OpenShift Overview - Red Hat Open House 2017
OpenShift Overview - Red Hat Open House 2017OpenShift Overview - Red Hat Open House 2017
OpenShift Overview - Red Hat Open House 2017Rodolfo Carvalho
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and ContainersRodolfo Carvalho
 

More from Rodolfo Carvalho (7)

Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX Go
 
OpenShift Overview - Red Hat Open School 2017
OpenShift Overview - Red Hat Open School 2017OpenShift Overview - Red Hat Open School 2017
OpenShift Overview - Red Hat Open School 2017
 
OpenShift Overview - Red Hat Open House 2017
OpenShift Overview - Red Hat Open House 2017OpenShift Overview - Red Hat Open House 2017
OpenShift Overview - Red Hat Open House 2017
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
Go 1.8 Release Party
Go 1.8 Release PartyGo 1.8 Release Party
Go 1.8 Release Party
 
A Tour of Go - Workshop
A Tour of Go - WorkshopA Tour of Go - Workshop
A Tour of Go - Workshop
 
XMPP
XMPPXMPP
XMPP
 

Recently uploaded

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

Rodolfo Carvalho - TDD and Perl Best Practices

  • 1. Rodolfo Carvalho - @201 YAPC::Brasil 2011
  • 2. Rodolfo Carvalho ● Eng. Computação UFRJ ● PythOnRio ● Coding Dojo Rio ● Ex-Globo.com, ex-Intelie ● Entusiasta de Racket ● Monge Perl? Quem sabe em breve :P
  • 3. CPAN: Comprehensive Perl Archive Network metacpan.org
  • 4. Desenvolvimento "tradicional" Design Code Test
  • 5. TDD: Test-Driven Development Design Test Test Refacto r Code
  • 6.
  • 7. No longo prazo... x ... tempo
  • 8. Em Perl ● CPAN contém diversas opções ● TAP: "Test Anything Protocol" Test::Simple Test::More + Test::Exception Test::Differences Test::Deep + prove Test::Warn = Test::Most
  • 9. Exemplo Problema: calcular o n-ésimo número da sequência de Fibonacci. Design: escrever uma função que recebe um argumento numérico (n) e retorna o número da sequência correspondente.
  • 10. Exemplo: Fibonacci Teste: Resultado: use Test::More; $ prove fibonacci.pl fibonacci.pl .. Undefined subroutine &main::fibonacci is( fibonacci(0), 0 ); called at fibonacci.pl line 4. fibonacci.pl .. Dubious, test returned 9 (wstat 2304, done_testing(); 0x900)
  • 11. Exemplo: Fibonacci Implementação: Resultado: sub fibonacci { $ prove fibonacci.pl fibonacci.pl .. ok return 0; All tests successful. }
  • 13. Exemplo: Fibonacci Teste: Implementação: is( fibonacci(0), 0 ); sub fibonacci { my $n = shift; is( fibonacci(1), 1 ); return 0 if $n eq 0; is( fibonacci(2), 1 ); return 1 if $n eq 1; return 1 if $n eq 2; }
  • 14. Exemplo: Fibonacci Teste: Resultado: is( fibonacci(0), 0 ); $ prove fibonacci.pl fibonacci.pl .. 1/? is( fibonacci(1), 1 ); # Failed test at fibonacci.pl is( fibonacci(2), 1 ); line 15. is( fibonacci(3), 2 ); # got: '' # expected: '2' # Looks like you failed 1 test of 4.
  • 15. Exemplo: Fibonacci Implementação: Resultado: sub fibonacci { $ prove fibonacci.pl my $n = shift; fibonacci.pl .. ok return 0 if $n eq 0; All tests successful. return 1 if $n eq 1; return fibonacci($n-2) + fibonacci($n-1); }
  • 16. Exemplo: Fibonacci Teste: Resultado: my $phi = (1+sqrt 5)/2; $ prove fibonacci.pl my $psi = -1/$phi; fibonacci.pl .. ok foreach ( 0..20 ) { All tests successful. is( fibonacci($_), ($phi**$_ - $psi**$_)/ sqrt 5 ); }
  • 18. package Example::Test; use base qw(Test::Class); use Test::More; OOP's "xUnit" # setup methods are run before every test method. sub make_fixture : Test(setup) { my $array = [1, 2]; shift->{test_array} = $array; ● Test::Class }; # a test method that runs 1 test sub test_push : Test { my $array = shift->{test_array}; push @$array, 3; is_deeply($array, [1, 2, 3], 'push worked'); }; ● Test::MockObject # a test method that runs 4 tests sub test_pop : Test(4) { my $array = shift->{test_array}; ● DBD::Mock is(pop @$array, 2, 'pop = 2'); is(pop @$array, 1, 'pop = 1'); is_deeply($array, [], 'array empty'); is(pop @$array, undef, 'pop = undef'); ● Test::TCP }; # teardown methods are run after every test method. sub teardown : Test(teardown) { my $array = shift->{test_array}; diag("array = (@$array) after test(s)"); };
  • 19. TDD + Web ● Test::WWW::Mechanize use Test::More tests => 5; use Test::WWW::Mechanize; my $mech = Test::WWW::Mechanize->new; $mech->get_ok( $page ); $mech->base_is( 'http://petdance.com/', 'Proper <BASE HREF>' ); $mech->title_is( 'Invoice Status', "Make sure we're on the invoice page" ); $mech->text_contains( 'Andy Lester', 'My name somewhere' ); $mech->content_like( qr/(cpan|perl).org/, 'Link to perl.org or CPAN' );
  • 20. TDD + Web use Test::More tests => 10; ● Test::Mojo use Test::Mojo; my $t = Test::Mojo->new('MyApp'); $t->get_ok('/welcome') ->status_is(200) HTML5 ->content_like(qr/Hello!/, 'welcome message'); $t->post_form_ok('/search', {title => 'Perl', author => 'taro'}) ->status_is(200) ->content_like(qr/Perl.+taro/); Real-time webapps $t->delete_ok('/something') ->status_is(200) ->header_is('X-Powered-By' => 'Mojolicious (Perl)') ->header_isnt('X-Bender' => 'Bite my shiny metal ass!'); ->content_is('Hello world!'); $t->websocket_ok('/echo') ->send_message_ok('hello') ->message_is('echo: hello') ->finish_ok;
  • 21. Test anything... ● Test::Pod::Coverage ● Test::UseAllModules ● Test::NoWarnings ● Test::Perl::Critic ● Test::AskAnExpert ● Test::Inline ● Test::UniqueTestNames
  • 22. Não basta escrever testes Fácil: ● Dada uma entrada, comparar saída e saída esperada Difícil: ● O que testar ● Como testar ● Erros não previstos
  • 23. Não basta escrever testes Short list of ways tests could fail without any code change: ● "Temporary" test files and fixtures might be dirty. ● "Temporary" databases and tables might be dirty. ● It is sensitive to time or date. ● It uses network resources and they changed. ● The compiler was changed. ● The installed libraries used were changed. ● The libraries the libraries use were changed. ● The kernel was changed. ● Any servers used (databases, web servers, etc...) were changed. ● It uses parallel processing and a subtle bug only occurs sometimes. ● The disk (or the filesystem where temp files go) is full. ● The disk (or the filesystem where temp files go) is broken. ● Your memory/disk/process/filehandle quotas were reduced. ● The machine has run out of memory. ● The machine has run out of filehandles. ● It uses fixtures with randomly generated data and generated some that tickled a bug. Michael Schwern
  • 25.
  • 26. Quero fazer TDD, e agora?
  • 28.
  • 29. Coding Dojo ● Prática deliberada de TDD ● Programação em par ● Aprendizado coletivo + é divertido!
  • 30. Como funciona? Precisamos de: ● Piloto e co-piloto ● Problema ● Computador ● Projetor ● Cronômetro ● Comida!
  • 31. 5 ~ 7 min
  • 33. Onde TDD + Perl Centro, toda quarta-feira às 18:30 UFF - Niterói Av Treze de Maio, 13 – sala 616 quintas 19:00 Edifício Municipal
  • 34.
  • 35. Agradecimentos Breno (Garu) Dojo Rio dojorio.org Contato about.me/rhcarvalho