Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

xsawyerx (8978)

xsawyerx
  (email not shown publicly)

Journal of xsawyerx (8978)

Thursday May 21, 2009
04:49 AM

Test::Class, Test::Able, Test::Dammit::Test

[ #39012 ]
update: the caveat mentioned at the bottom isn't of Test::Able. It's just how programming works

Today I tried to convert some standards tests that I have with Test::More and Test::Block (which is what I normally use for testing) to Test::Class.

First thought that came to my head was "I bet Moose could be useful here" and remembered Test::Able which I never really used. I quickly compared them both and found Test::Class to be shorter, so I started off with it.

The problems first appeared when I tried to convert the roles I had into inherited tests. They seem to work, only that the startup() method I had written is being performed on EVERY inherited test! What the fsck would be the point of writing a base test to inherit from, have startup methods in it and then re-run these for every possible inherited test? For every role test I'm going to ask the user for the same input he gave at the startup()? I had to rethink this.

I tried Test::Able which might be able to solve this more elegantly. I ported the Test::Class tests easily enough and even used attributes instead of tested hash values (leaving Moose to test some input for me), which was more comfortable. Then I set out to convert the inherited tests.

I started by writing them as roles since it seemed to make sense. First error:

Could not load class (Code::Test::Role) because : Code::Test::Role already has a metaclass, but it does not inherit Moose::Meta::Class

Checking Test::Able, we can see that it has roles support under Test::Able::Role. Whoops, my mistake! Using Test::Able::Role my tests now work, except when I try: test plan => 3, test_method => sub { }; Apparently Test::Able::Role doesn't support multiple tests per method. Alright, lets try setting the plan inside the method:

test test_method => sub {
    $_[0]->meta->current_method->plan(3);
    ok( 1, "test $_" ) for 1 .. 3;
};

This works. Finally I can run tests. One caveat I've noticed is that one of tests in the test class was done first, while another one was done last. This is not a caveat in Test::Able, this is just how methods work in programming. Perhaps I should keep those tests at the startup() unless they don't mean anything to the roles.

Thank you Justin DeVuyst for Test::Able!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.