Pacific-Design.com

    
Home Index

1. Perl5

2. Unit Test

3. Moose

Perl5 / Unit Test / Moose /

moose_class.pm

package moose_class;
use Moose;    # automatically turns on strict and warnings

has 'x' => (is => 'rw', isa => 'Int');
has 'y' => (is => 'rw', isa => 'Int');

sub clear
{
    my $self = shift;
    $self->x(0);
    $self->y(0);
}

1;

test.t

#/usr/bin/perl
use Test::Moose;
use Test::More;
use moose_class;

my $moose_class = moose_class->new();

has_attribute_ok($moose_class, 'x' ); 
has_attribute_ok($moose_class, 'x' ); 

done_testing();

Run Unit Test on Moose

perl -MDevel::Cover test.t
Selecting packages matching:
Ignoring packages matching:
    /Devel/Cover[./]
Ignoring packages in:
    .
    /vcm/home/apps/perl-5.12.1/lib/5.12.1
    /vcm/home/apps/perl-5.12.1/lib/5.12.1/x86_64-linux
    /vcm/home/apps/perl-5.12.1/lib/site_perl/5.12.1
    /vcm/home/apps/perl-5.12.1/lib/site_perl/5.12.1/x86_64-linux
    /vcm/home/lib/perl
ok 1 - The object does has an attribute named x
ok 2 - The object does has an attribute named x
1..2
Devel::Cover: Writing coverage database to /home/kduraj/cover_sandbox/cover_db/runs/1328050267.11501.56114
---------------------------- ------ ------ ------ ------ ------ ------ ------
File                           stmt   bran   cond    sub    pod   time  total
---------------------------- ------ ------ ------ ------ ------ ------ ------
moose_class.pm                 50.0    n/a    n/a   50.0    0.0   39.5   44.4
test.t                        100.0    n/a    n/a  100.0    n/a   60.5  100.0
Total                          84.2    n/a    n/a   80.0    0.0  100.0   80.0
---------------------------- ------ ------ ------ ------ ------ ------ ------