The document describes Test::Kit 2.0, a module that allows creating custom test modules with desired test features. It allows combining behaviors from multiple test modules, excluding or renaming exported subs, and directly passing parameters to module imports. The document provides an example of creating a test kit and using it, and discusses benefits like reduced boilerplate and consistent testing. It also describes improvements made in Test::Kit 2.0 over the previous version.
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' ],
};
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';
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(-)
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';
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