test::kit 2.0 (london.pm technical meeting july 2014)
DESCRIPTION
A 15 minute introduction to using Test::Kit to reduce boilerplate in your Perl tests.TRANSCRIPT
Test::Kit 2.0custom test modules with the features you want
Alex Balhatchet @ London.pm Technical Meeting, July 2014
Hi there!
Hi there!
● Alex Balhatchet
● CTO at Nestoria
● Big fan of London.pm technical meetings
Test::Kit
Creating your Kit
Creating your Kitpackage MyProject::Test;
use Test::Kit;
Creating your Kitpackage MyProject::Test;
use Test::Kit;
# Combine multiple modules' behaviour into one include 'Test::More';include 'Test::LongString';
Creating your Kitpackage 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' },};
Creating your Kitpackage 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' ],};
Creating your Kitpackage 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' ],};
Using your Kit
Using your Kituse strict;use warnings; use MyProject::Test tests => 4;
Using your Kituse 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");
Using your Kituse 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";
Using your Kituse 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';
Using your Kituse 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';
2.0
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
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
Why use Test::Kit?
● Reduce boilerplate
● Be more consistent
● Easily add behaviour to all your tests
● 1322 files changed,2325 insertions(+),7549 deletions(-)
Nestoria Kit
The Nestoria Kit
# basicsinclude 'Test::More';
# outputs, warnings and exceptionsinclude 'Test::FailWarnings', 'Test::Warn', 'Test::Exception', 'Test::Output';
# files, data and data structuresinclude 'Test::File', 'Test::LongString', 'Test::JSON';include 'Test::Deep' => { 'exclude' => [ qw(all any) ] };
The Nestoria Kit
# mockinginclude 'Test::MockObject', 'Test::MockObject::Extends', 'Test::MockModule';
# utilitiesinclude 'Data::Dumper';
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)";
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"; } }}
Actively Maintained!
import::Into 1.002003
● Changed behaviour
● Flagged up as failures on CPAN Testers
● Test::Kit 2.01 released 2 days later
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
See Also
See Also
● ToolSet
● Import::Base
● Import::Into
● Test::Builder::Provider
Questions?