So, I know enough about the basics of test driven development to want to start worrying about how to make things more painless. I've got code like this in my tests to make sure my Moose classes has the attributes/methods/packages it needs to run correctly:
ok $INC{'DB.pm'}, 'DB module loaded'; ok $INC{'Moose.pm'}, 'Moose module loaded'; ok $INC{'StevesPerlTools.pm'}, 'StevesPerlTools module loaded'; ok $INC{'Modern/Perl.pm'}, 'Modern::Perl module loaded'; ok $INC{'LaborData/Data/Dir.pm'}, 'LaborData::Data::Dir module loaded' +; ok $INC{'StevesPerlTools.pm'}, 'StevesPerlTools module loaded'; #ok $INC{'Web/Scraper.pm'}, 'Web::Scraper module loaded'; my $i; lives_ok { $i = LaborData::Data::Importer->new } 'does not throw error + with no argument passed'; # check that needed attributes are created and are proper type is 1, $i->meta->has_attribute('raw_data'), 'has an \'raw_data\' attrib +ute'; is 'LaborData::Data::Dir', $i->meta->get_attribute('raw_data')->type_c +onstraint, 'raw_data attribute is a \'LaborData::Data::Dir\''; is (attribute_is_ro($i, 'raw_data'), 1, 'raw_data is read only'); is (!! $i->can('create_db'), 1, 'can create database'); is (!! $i->can('destroy_db'),1, 'can destroy database'); is 1, !! $i->can('_get_columns'), 'can get columns'; # etc;
Obviously, a lot of this is repetitive and it's a lot of typing for stuff that will probably pass once and will likely never break again. Still, I'd feel better if I did test my class as a sanity check. I'm assuming there is some kind of framework for automating this. I've looked briefly at Test::Class::Moose but I'm not quite sure if it can help automate the kind of tests I'm running in my code above (like attribute properties, for example).
And guidance is appreciated.
UPDATE As I think about this more, I guess what I'd be looking for is to be able to write a class definition into some file and run a script that would automatically generate the Moose class and the tests for me. Does such a beast exist?
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
In reply to Automation of testing of Moose class structure by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |