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!
This is why I love opensource
xsawyerx on 2009-05-21T21:56:15
Submitted at: https://rt.cpan.org/Ticket/Display.html?id=46290
Thanks!