0
Test   automatici2
                 per
  applicazioni Web
 Stefano Rodighiero - larsen@perl.it
Scrivere software
           =
Gestire la complessità
Complessità

You might think of this as mental juggling - the more mental
balls the program requires you to keep in the ai...
Gestire la complessità

• Loose coupling
• Tecniche standard
• KISS
• Test?
Test?

    «Testing by itself does not improve software quality. [...]
Trying to improve software by increasing the amount...
Test!
• Aumenta indirettamente la qualità del
  software
• Design for testing
• Refactoring
• Wishful thinking
• Confidenza...
Esempio

#!/usr/bin/perl -w

use Test::Simple tests => 2;
use Date::ICal;

my $ical = Date::ICal->new;     # make an objec...
Gradualmente

• prova.pl → t/01_base.t
• diag()
• Usare gli occhi
• map <F8> :! prove        %<C-M>
• YMMV :)
Applicazioni web
Paradigma MVC

    Presentazione   Model




      Controllo
Test di videogame


• Situazioni difficili da riprodurre
• Grande complessità
• Chi effettua il test non è il programmatore
?
Test di applicazioni web


• Workflow complessi
• Quello che non è automatico tende a non
  essere fatto
WWW::Mechanize
#!/usr/bin/perl

use strict;
use warnings;

use WWW::Mechanize;

my $agent = WWW::Mechanize->new();
$agent-...
Test::WWW::Mechanize
#!/usr/bin/perl

use strict;
use warnings;

use Test::More qw/ no_plan /;
use Test::WWW::Mechanize;

...
WWW::Mechanize::Shell

calvin:~ larsen$ perl -MWWW::Mechanize::Shell -e shell
>g http://www.google.com
Retrieving http://w...
WWW::Mechanize::Shell
 #!perl -w
 use strict;
 use WWW::Mechanize;
 use WWW::Mechanize::FormFiller;
 use URI::URL;

 my $a...
HTTP::Recorder
proxy.pl
#!/usr/bin/perl

use strict;
use warnings;

use HTTP::Proxy qw/ :log /;
use HTTP::Recorder;

my $proxy = HTTP::Pr...
Demo
Idee

• Usare proxy.pl con un sistema di bugtracking
  (il ticket contiene il codice per riprodurre
  l’errore)
• Testare ...
Conclusioni

• Integrate le pratiche di testing nel vostro
  workflow lavorativo
• Gradualmente!
• Sono pratiche che pagano...
Monday, I could wait till Tuesday
If I make up my mind
Wednesday would be fine, Thursday’s on my mind
Friday’d give me time...
Grazie :)

      larsen@perl.it
http://larsen.perlmonk.org/blog
Riferimenti
• Web Testing with HTTP::Recorder
  http://www.perl.com/pub/a/2004/06/04/recorder.html
• Test di applicazioni ...
Test Automatici^2 per applicazioni Web
Test Automatici^2 per applicazioni Web
Test Automatici^2 per applicazioni Web
Test Automatici^2 per applicazioni Web
Test Automatici^2 per applicazioni Web
Test Automatici^2 per applicazioni Web
Upcoming SlideShare
Loading in...5
×

Test Automatici^2 per applicazioni Web

1,891

Published on

An introduction to testing tecniques for web applications, using WWW::Mechanize and HTTP::Recorder

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,891
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Test Automatici^2 per applicazioni Web"

  1. 1. Test automatici2 per applicazioni Web Stefano Rodighiero - larsen@perl.it
  2. 2. Scrivere software = Gestire la complessità
  3. 3. Complessità You might think of this as mental juggling - the more mental balls the program requires you to keep in the air at once, the more likely you’ll drop one of the balls, leading to a design or coding error. -- Steve McConnell
  4. 4. Gestire la complessità • Loose coupling • Tecniche standard • KISS • Test?
  5. 5. Test? «Testing by itself does not improve software quality. [...] Trying to improve software by increasing the amount of testing is like trying to lose weight by weighting yourself more often» -- Steve McConnell
  6. 6. Test! • Aumenta indirettamente la qualità del software • Design for testing • Refactoring • Wishful thinking • Confidenza con il proprio codice
  7. 7. Esempio #!/usr/bin/perl -w use Test::Simple tests => 2; use Date::ICal; my $ical = Date::ICal->new; # make an object ok( defined $ical ); # check we got something ok( $ical->isa('Date::ICal') ); # and it's the right class
  8. 8. Gradualmente • prova.pl → t/01_base.t • diag() • Usare gli occhi • map <F8> :! prove %<C-M> • YMMV :)
  9. 9. Applicazioni web
  10. 10. Paradigma MVC Presentazione Model Controllo
  11. 11. Test di videogame • Situazioni difficili da riprodurre • Grande complessità • Chi effettua il test non è il programmatore
  12. 12. ?
  13. 13. Test di applicazioni web • Workflow complessi • Quello che non è automatico tende a non essere fatto
  14. 14. WWW::Mechanize #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $agent = WWW::Mechanize->new(); $agent->get( 'http://www.google.com' ); print $agent->content();
  15. 15. Test::WWW::Mechanize #!/usr/bin/perl use strict; use warnings; use Test::More qw/ no_plan /; use Test::WWW::Mechanize; my $agent = Test::WWW::Mechanize->new(); $agent->get_ok( 'http://www.google.com' ); $agent->title_is( 'Google' );
  16. 16. WWW::Mechanize::Shell calvin:~ larsen$ perl -MWWW::Mechanize::Shell -e shell >g http://www.google.com Retrieving http://www.google.com(200) http://www.google.com>script mech3.pl http://www.google.com>quit calvin:~ larsen$
  17. 17. WWW::Mechanize::Shell #!perl -w use strict; use WWW::Mechanize; use WWW::Mechanize::FormFiller; use URI::URL; my $agent = WWW::Mechanize->new( autocheck => 1 ); my $formfiller = WWW::Mechanize::FormFiller->new(); $agent->env_proxy(); $agent->get('http://www.google.com'); $agent->form(1) if $agent->forms and scalar @{$agent->forms}; mech3.pl
  18. 18. HTTP::Recorder
  19. 19. proxy.pl #!/usr/bin/perl use strict; use warnings; use HTTP::Proxy qw/ :log /; use HTTP::Recorder; my $proxy = HTTP::Proxy->new; my $agent = HTTP::Recorder->new( file => quot;/tmp/tmpfilequot; , showwindow => 1 ); $proxy->logmask( STATUS | PROCESS | HEADERS ); $proxy->port( 3128 ); $proxy->host( '' ); $proxy->agent( $agent ); $proxy->start();
  20. 20. Demo
  21. 21. Idee • Usare proxy.pl con un sistema di bugtracking (il ticket contiene il codice per riprodurre l’errore) • Testare applicazioni non scritte in Perl • Screenscraping
  22. 22. Conclusioni • Integrate le pratiche di testing nel vostro workflow lavorativo • Gradualmente! • Sono pratiche che pagano da subito • Come posso progettare il codice per facilitarne il test?
  23. 23. Monday, I could wait till Tuesday If I make up my mind Wednesday would be fine, Thursday’s on my mind Friday’d give me time, Saturday could wait But Sunday’d be too late -- Sting
  24. 24. Grazie :) larsen@perl.it http://larsen.perlmonk.org/blog
  25. 25. Riferimenti • Web Testing with HTTP::Recorder http://www.perl.com/pub/a/2004/06/04/recorder.html • Test di applicazioni web http://www.perl.it/blog/archives/000036.html • A Perl Testing Tutorial (PDF) http://www.wgz.org/chromatic/perl/IntroTestMore.pdf • Migliorare la navigazione sul web con Perl http://www.perl.it/blog/archives/000076.html • Documentazione dei vari moduli menzionati http://search.cpan.org/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×