Test::Kit 2.0 (London.pm Technical Meeting July 2014)
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Test::Kit 2.0 (London.pm Technical Meeting July 2014)

on

  • 371 views

A 15 minute introduction to using Test::Kit to reduce boilerplate in your Perl tests.

A 15 minute introduction to using Test::Kit to reduce boilerplate in your Perl tests.

Statistics

Views

Total Views
371
Views on SlideShare
370
Embed Views
1

Actions

Likes
0
Downloads
0
Comments
0

1 Embed 1

http://www.slideee.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Test::Kit 2.0 (London.pm Technical Meeting July 2014) Presentation Transcript

  • 1. Test::Kit 2.0 custom test modules with the features you want Alex Balhatchet @ London.pm Technical Meeting, July 2014
  • 2. Hi there!
  • 3. Hi there! ● Alex Balhatchet ● CTO at Nestoria ● Big fan of London.pm technical meetings
  • 4. Test::Kit
  • 5. Creating your Kit
  • 6. Creating your Kit package MyProject::Test; use Test::Kit;
  • 7. Creating your Kit package MyProject::Test; use Test::Kit; # Combine multiple modules' behaviour into one include 'Test::More'; include 'Test::LongString';
  • 8. Creating your Kit package MyProject::Test; use Test::Kit; # Combine multiple modules' behaviour into one include 'Test::More'; include 'Test::LongString'; # Exclude or rename exported subs include 'Test::Warn' => { exclude => [ 'warning_is' ], renamed => { 'warning_like' => 'test_warn_warning_like' }, };
  • 9. Creating your Kit package MyProject::Test; use Test::Kit; # Combine multiple modules' behaviour into one include 'Test::More'; include 'Test::LongString'; # Exclude or rename exported subs include 'Test::Warn' => { exclude => [ 'warning_is' ], renamed => { 'warning_like' => 'test_warn_warning_like' }, }; # Pass parameters through to import() directly include 'List::Util' => { import => [ 'min', 'max', 'shuffle' ], };
  • 10. Creating your Kit package MyProject::Test; use Test::Kit; # Combine multiple modules' behaviour into one include 'Test::More'; include 'Test::LongString'; # Exclude or rename exported subs include 'Test::Warn' => { exclude => [ 'warning_is' ], renamed => { 'warning_like' => 'test_warn_warning_like' }, }; # Pass parameters through to import() directly include 'List::Util' => { import => [ 'min', 'max', 'shuffle' ], };
  • 11. Using your Kit
  • 12. Using your Kit use strict; use warnings; use MyProject::Test tests => 4;
  • 13. Using your Kit use strict; use warnings; use MyProject::Test tests => 4; ok 1, "1 is true"; like_string( `cat /usr/share/dict/words`, qr/^ kit $/imsx, "kit is a word" );
  • 14. Using your Kit use strict; use warnings; use MyProject::Test tests => 4; ok 1, "1 is true"; like_string( `cat /usr/share/dict/words`, qr/^ kit $/imsx, "kit is a word" ); test_warn_warning_like { warn "foo"; } qr/FOO/i, "warned foo";
  • 15. Using your Kit use strict; use warnings; use MyProject::Test tests => 4; ok 1, "1 is true"; like_string( `cat /usr/share/dict/words`, qr/^ kit $/imsx, "kit is a word" ); test_warn_warning_like { warn "foo"; } qr/FOO/i, "warned foo"; is max(qw(1 2 3 4 5)), 5, 'maximum is 5';
  • 16. Using your Kit use strict; use warnings; use MyProject::Test tests => 4; ok 1, "1 is true"; like_string( `cat /usr/share/dict/words`, qr/^ kit $/imsx, "kit is a word" ); test_warn_warning_like { warn "foo"; } qr/FOO/i, "warned foo"; is max(qw(1 2 3 4 5)), 5, 'maximum is 5';
  • 17. 2.0
  • 18. 2.0 ● 0.101 was written by Ovid ● Really cool idea! ● Unfortunately broken… ○ Didn’t work with Test::Aggregate ○ Only worked in package main ○ Complicated “features” architecture
  • 19. 2.0 ● Saw Matt Trout talk about Import::Into at LPW 2013 ● Realised it probably solved half the problems with Ovid’s Test::Kit ● Rewrote it from scratch as Test::Kit2 ● Got COMAINT from Ovid so I could release it as Test::Kit 2.0
  • 20. Why use Test::Kit? ● Reduce boilerplate ● Be more consistent ● Easily add behaviour to all your tests ● 1322 files changed, 2325 insertions(+), 7549 deletions(-)
  • 21. Nestoria Kit
  • 22. The Nestoria Kit # basics include 'Test::More'; # outputs, warnings and exceptions include 'Test::FailWarnings', 'Test::Warn', 'Test::Exception', 'Test::Output'; # files, data and data structures include 'Test::File', 'Test::LongString', 'Test::JSON'; include 'Test::Deep' => { 'exclude' => [ qw(all any) ] };
  • 23. The Nestoria Kit # mocking include 'Test::MockObject', 'Test::MockObject::Extends', 'Test::MockModule'; # utilities include 'Data::Dumper';
  • 24. The Nestoria Kit binmode Test::More->builder->output, ":encoding(utf8)"; binmode Test::More->builder->failure_output, ":encoding(utf8)"; binmode Test::More->builder->todo_output, ":encoding(utf8)";
  • 25. The Nestoria Kit { my @req_env_vars = ( 'LOKKU_CODE', 'LOKKU_COMMON', 'LOKKU_BIGSLOW', ); foreach my $env_var (@req_env_vars) { if(!$ENV{$env_var}) { die "Environment variable '$env_var' not set"; } } }
  • 26. Actively Maintained!
  • 27. import::Into 1.002003 ● Changed behaviour ● Flagged up as failures on CPAN Testers ● Test::Kit 2.01 released 2 days later
  • 28. Test::Builder 1.301001_013 ● Dev release of Test::Builder! ● Test::Builder::Module deprecated ● Again, flagged on CPAN Testers ● Not fixed yet, but will be very soon
  • 29. See Also
  • 30. See Also ● ToolSet ● Import::Base ● Import::Into ● Test::Builder::Provider
  • 31. Questions?
  • 32. N estoria is H iring! http://lokku.com /jobs Thanks!