Test::Class::Most

I'm really tired of boilerplate. In fact, I hate it so much that I can't stand when I write this:

package Some::Test::Class;
use strict;
use warnings;
use base 'My::Test::Class';
use Test::More;
use Test::Exception;

Of course, you already know about Test::Most and Modern::Perl, so you could reduce it to this:

package Some::Test::Class;
use base 'My::Test::Class';
use Modern::Perl;
use Test::Most;

But that's still boilerplate. So here's what I've just uploaded:

package Some::Test::Class;
use Test::Class::Most parent => 'My::Test::Class';

That gets you strict, warnings, all test functions from Test::Most and, if you have 5.10 or better, all the modern features of Modern::Perl. It (reluctantly) supports multiple inheritance (pass an arrayref of class names as the value to 'parent') and if you don't want the modern features, you can do this:

package Some::Test::Class;
use Test::Class::Most parent => 'My::Test::Class', feature => 0;

To create your own Test::Class base class (which inherits directly from Test::Class), just don't specify an import list:

package My::Test::Class;
use Test::Class::Most;

The documentation includes links to my Test::Class tutorials for those not familiar with it:

  1. Organizing your test suites
  2. Reusing test code
  3. Making Test::Class easier to use
  4. Test control methods
  5. Final tips and summary

Test::Class::Most is not quite as pretty as Piers Cawley's lovely Test::Class::Sugar, but it has far less magic. I think the docs are clear, but if they confuse you see the the Test::Class tests I ship with it for a good example. Hopefully it will make your test classes much more pleasant to write.

1 Comment

Ovid, thank you for the code.

About Ovid

user-pic Freelance Perl/Testing/Agile consultant and trainer. See http://www.allaroundtheworld.fr/ for our services. If you have a problem with Perl, we will solve it for you. And don't forget to buy my book! http://www.amazon.com/Beginning-Perl-Curtis-Poe/dp/1118013840/