Intermediate Perl Testing (or, Let's Not Make A Mess Of Things, Shall We?)

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite & 2 Groups

    Intermediate Perl Testing (or, Let's Not Make A Mess Of Things, Shall We?) - Presentation Transcript

    1. Intermediate Perl Testing (or, Let’s Not Make A Mess Of Things, Shall We?) Josh Heumann
    2. Have you seen these tests? is_deeply( get_recipes(), [qw/ lemon_curd pancakes enchiladas /], ‘all of the recipes are there’ ); SKIP: { skip ‘No ingredients’, 2, if @ingredients < 1; is( $number, 23, ‘and the number is 23’ ); }; dies_ok( sub { eat_cake }, qr/Cake isn’t chocolate/, ‘only eat chocolate cake’ );
    3. What this talk will do
    4. What this talk won’t do
    5. Why Have Altercations That Encourage Violent Excitable Rants?
    6. Why Have Altercations That Encourage Violent Excitable Rants?
    7. Make them easy to run
    8. Run early, run often
    9. Blackbox testing
    10. Blackbox testing
    11. Blackbox testing
    12. Glassbox testing
    13. Whatever.
    14. Testing scripts #!/usr/bin/perl use strict; use warnings; get_jiggy(); sub get_jiggy { # details, details }
    15. Testing scripts __FILE__
    16. Testing scripts __FILE__ .pl gy g ji t_ ge in/ b
    17. Testing scripts $0
    18. Testing scripts $0 AKA $PROGRAM_NAME
    19. Testing scripts $0 AKA $PROGRAM_NAME pl y. g jig _ et /g in b
    20. Testing scripts $0 AKA $PROGRAM_NAME psl.t . ys ge jggin i ig j_ et t_ es g /bin/ t t
    21. Testing scripts $0 __FILE__ != <> s.tne .pl es ≠ in gy igg g ji j t_ t_ ge es t in/ t/ b
    22. Testing scripts $0 __FILE__ eq == .pl gy .pl g ji gy t_ g ji ge t_ in/ ge b in/ b
    23. Testing scripts #!/usr/bin/perl use strict; use warnings; get_jiggy() if $0 eq __FILE__; sub get_jiggy { # details, details }
    24. Testing scripts #!/usr/bin/perl use strict; use warnings; use Test::More tests => 42; require_ok( ‘bin/get_jiggy.pl’ ); can_ok( ‘main’, ‘get_jiggy’, ‘jigginess achieved’ ); # test the details
    25. Code coverage
    26. Code coverage cover -test
    27. Code coverage cover -test ./Build testcover
    28. Code coverage cover -test ./Build testcover HARNESS_PERL_SWITCHES=-MDevel::Cover make test
    29. Demonstration time!
    30. Version control
    31. Version control
    32. Version control
    33. Testing and version control ?
    34. Testing and version control
    35. Testing and version control
    36. Testing and version control
    37. Testing and version control
    38. Testing and version control
    39. Testing and version control
    40. Testing and version control
    41. Testing and version control
    42. Testing and version control
    43. Testing and version control
    44. Testing and version control
    45. Version control
    46. Reusing test code
    47. Reusing test code for(qw/ is_hilarious is_annoying is_bewildering /) { can_ok( Child, $_ ); is( Child->$_, 1, “...and the child $_” ); }
    48. Reusing test code sub _test_accessor { my ( $method ) = @_; my $getter = \"get_$method\"; my $setter = \"set_$method\"; can_ok( 'Cat', $getter ); can_ok( 'Cat', $setter ); is( Cat->new->$getter, undef, \"...and $method is undef to start with\" ); .... } _test_accessor( ‘sleep’ );
    49. Reusing test code sub _test_accessor { my ( $method ) = @_; my $getter = \"get_$method\"; my $setter = \"set_$method\"; can_ok( 'Cat', $getter ); can_ok( 'Cat', $setter ); is( Cat->new->$getter, undef, \"...and $method is undef to start with\" ); .... } _test_accessor( $_ ) for(qw/ sleep eat purr /);
    50. Whatever.
    51. Custom test libraries
    52. Custom test libraries $ prove t t/00_basics....ok All tests successful. Files=1, Tests=377, 1 wallclock secs ( 0.17 cusr + 0.02 csys = 0.19 CPU)
    53. Custom test libraries package Test::Clowns; use Test::Builder; use Perl6::Junction qw/ any /; my $Test = Test::Builder->new; sub test_clowns { my($clown, $name) = @_; $clown->hop_out_of_a_very_small_car(); $Test->ok( $clown->can_juggle, $name ); $Test->ok( $clown->has_pies, $name ); if( any($clown->faces) eq ‘scary’ ) { $Test->fail( “clowns shouldn’t be scary” ); } $Test->ok( $clown->is_scary, $name ); }
    54. Custom test libraries use TAP::Harness; my $harness = TAP::Harness->new( verbose => 1, lib => [ 'lib', 'blib/lib' ], ); $harness->runtests(@tests); +
    55. Fixtures
    56. our %clients = ( 1001 => { client_id => 1001, dob => '1926-05-25', fname => 'Miles', lname => 'Davis', sex => 'Male', race => 'Black', marital_status => 'Divorced', substance_abuse => 'Yes', alcohol_abuse => 'Yes', gambling_abuse => 'Unknown', religion => 'Muslim', },
    57. 1002 => { client_id => 1002, dob => '1922-04-21', fname => 'Charles', lname => 'Mingus', sex => 'Male', race => 'Other', marital_status => 'Married', substance_abuse => 'No', alcohol_abuse => 'Yes', gambling_abuse => 'Unknown', religion => 'Buddhist', }, # etc, # etc, # etc. );
    58. for my $client_id (keys %clients) { Test::Client->new( id => $clients{ $client_id } )->save; }
    59. for my $client_id (keys %clients) { Test::Client->new( id => $clients{ $client_id } )->save; } Test::Client->new(1001)->save;
    60. sub create_test_client { Test::Client->new( %args )->save; } create_test_client( id => 2, dob => undef, );
    61. sub create_test_client { $args{ dob } ||= ‘1970-01-01’; Test::Client->new( %args )->save; } create_test_client( id => 2, dob => undef, );
    62. sub create_test_client { $args{ dob } ||= ‘1970-01-01’; $args{ shrink } ||= create_test_shrink; Test::Client->new( %args )->save; } create_test_client( id => 2, dob => undef, );
    63. Mocking
    64. Mocking
    65. Mocking Test::MockObject
    66. Mocking Test::MockObject Test::MockClass
    67. Mocking Test::MockObject Test::MockClass Sub::Override
    68. Mocking Test::MockDBI Test::Mock::LWP Test::Mock::HTTP::Request Test::Mock::HTTP::Response
    69. Selenium
    70. How to win friends and convince others to test
    71. Speeding up tests
    72. Where to start?
    73. Review
    74. Review Make your tests easy to run
    75. Review Make your tests easy to run Run them often
    76. Review Make your tests easy to run Run them often Test your modules
    77. Review Make your tests easy to run Run them often Test your modules Test your scripts
    78. Review Make your tests easy to run Run them often Test your modules Test your scripts Improve your code coverage with Devel::Cover
    79. Review Make your tests easy to run Run them often Test your modules Test your scripts Improve your code coverage with Devel::Cover Use version control, and check in often
    80. Review Make your tests easy to run Run them often Test your modules Test your scripts Improve your code coverage with Devel::Cover Use version control, and check in often Reuse your test code
    81. Review
    82. Review Make a test library
    83. Review Make a test library Use fixtures
    84. Review Make a test library Use fixtures Mock when necessary
    85. Review Make a test library Use fixtures Mock when necessary Test quietly if you don’t have support
    86. Review Make a test library Use fixtures Mock when necessary Test quietly if you don’t have support Start with the most-changed part of the code
    87. Questions?
    88. Thanks! • Michael Schwern • Kirrily Robert • OSDC • realestate.com.au • you
    89. Josh Heumann josh@joshheumann.com

    + heumannheumann, 2 years ago

    custom

    646 views, 1 favs, 0 embeds more stats

    An overview of some methods of perl testing.

    More Info

    © All Rights Reserved

    Go to text version
    • Total Views 646
      • 646 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 31
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as innappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel

    Categories

    Tags

    Groups / Events