Entering MooseX, Part the Ninth

Well reaching the end of the road here now that I did my code review I think it is now about time I sit down and write up my first .t files for my Moosex.

I always think it is best to keep your tests simple and small, but not too small so I usually use Test::More as that give me just a few dependencies but a good load of extras. I am also little old school with my testing style as I like the good old numbered and named test that cover only one part of functionality.

So to start off I am going to start with good old 00-load.t

 
#!perl -T
use Test::More tests => 1;
use_ok('MooseX::AuthorizedMethodRoles');

and I give it a go

 

D:\Blogs\Moosex-AuthorizedMethodRoles\t\00-Load.t ..
1..1
ok 1 - use MooseX::AuthorizedMethodRoles;
ok
All tests successful.
Files=1, Tests=1, 0 wallclock secs ( 0.02 usr + 0.03 sys = 0.05 CPU)
Result: PASS

Well anyway that is very very basic and I think I can add a little more in here just to make sure everthing is correct on a load. That is when Test::Moose::More can help out a bunch. Now I am introducing some more dependencies but I can live with these.

Now I can add just a dummy class that I will use along with Test::Moose::More

 
{
package test;
use MooseX::AuthorizedMethodRoles;

}

and then add the most basic of Test::Moose::More tests simply validate the class.

 
validate_class 'test' => ();

and now I get

 

ok 1 - use MooseX::AuthorizedMethodRoles;
ok 2 - test has a metaclass
ok 3 - test is a Moose class
Dubious, test returned 255 (wstat 65280, 0xff00)
All 1 subtests passed
Test Summary Report
-------------------
D:\Blogs\Moosex-AuthorizedMethodRoles\t\00-Load.t (Wstat: 65280 Tests: 3 Failed: 2)
Failed tests: 2-3
Non-zero exit status: 255
Parse errors: Bad plan. You planned 1 tests but ran 3.
Files=1, Tests=3, 0 wallclock secs ( 0.00 usr + 0.05 sys = 0.05 CPU)
Result: FAIL

Opps got a Dubious there but I have written enough tests in my day to know that I forgot to put the correct test count at the top so a quick change to this

 
#!perl -T
use Test::More tests => 3;
use Test::Moose::More;
use_ok('MooseX::AuthorizedMethodRoles');
{
package test;
use MooseX::AuthorizedMethodRoles;

}
validate_class 'test' => ();

and I get

 
D:\Blogs\Moosex-AuthorizedMethodRoles\t\00-Load.t .. 
1..3
ok 1 - use MooseX::AuthorizedMethodRoles;
ok 2 - test has a metaclass
ok 3 - test is a Moose class
ok
All tests successful.
Files=1, Tests=3,  0 wallclock secs ( 0.03 usr +  0.00 sys =  0.03 CPU)
Result: PASS

ok that is one test down many more to go.

Now one might ask why break the test into little bits like this? Well the main reason is to isolate out any new functionality that comes in so it is easier to 'Test' new stuff as you just write a new test and run it rather that added a few new checks to a big test suite that you have to run from the beginning again.

Now it does not much matter on this small mod but on an extensive one like DBD::Oracle or DBI this approach saves a good deal of time and effort.

Now with my numbered and named tests I like to skip a few number between each main test so other that follow me can add in their test where they think best. So I will most likely start the next test with '10-', but that is another post

18t8h0gsfpnmrjpg.jpg

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations