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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.