I run Test::Fixme, Kwalitee, perl::Critic, etc ... on my modules but none of
them is ran on my tests. tests have a tendency to become a mess, be
undocumented, etc...
What are your thoughts, way of working that avoid the problems to start with
and is there a way to for the tests modules on the tests; a kind of
Test::Kwalitee::Tests
Cheers, Nadim.
> What are your thoughts, way of working that avoid the problems to
> start with
I organize my test files using an approach similar to nUnit - I create
a bunch of subroutines that each do a few assertions, and that call
set_up() and tear_down().
In my foo.t file I might have:
#-------------------------------------------
use strict;
use warnings;
use Readonly;
use Test::More tests => 10;
Readonly my $CLASS_UNDER_TEST => Foo::Bar;
use_ok($CLASS_UNDER_TEST);
test_foo();
test_bar();
test_baz();
exit;
sub set_up {
my $object = Foo::Bar->new();
return $object;
}
sub tear_down {
my @things_to_destroy = @_;
foreach $thing (@things_to_destroy) {
undef $thing;
}
return 1;
}
sub test_foo {
my $foo = set_up();
# do some assertions using $foo
return tear_down($foo);
}
sub test_bar {
my $foo = set_up();
# do some assertions using $foo
return tear_down($foo);
}
sub test_baz {
my $foo = set_up();
# do some assertions using $foo
return tear_down($foo);
}
#----------------------------
-------------------------------------------------------
Matisse Enzer <mat...@matisse.net>
http://www.matisse.net/ - http://www.eigenstate.net/
> I organize my test files using an approach similar to nUnit - I
> create
> a bunch of subroutines that each do a few assertions, and that call
> set_up() and tear_down().
...
> sub test_foo {
> my $foo = set_up();
> # do some assertions using $foo
> return tear_down($foo);
> }
>
> sub test_bar {
> my $foo = set_up();
> # do some assertions using $foo
> return tear_down($foo);
> }
>
> sub test_baz {
> my $foo = set_up();
> # do some assertions using $foo
> return tear_down($foo);
> }
You know, all of those set_up() and tear_down() calls are repetitive and can be factored out. Test::Class does that for you for free :)
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Perl and CGI - http://users.easystreet.com/ovid/cgi_course/
Personal blog - http://publius-ovidius.livejournal.com/
Tech blog - http://use.perl.org/~Ovid/journal/
> Hi, This mail is not discussing what quality and what test quality
> is. It is
> about what quality our 'test files' have.
>
> I run Test::Fixme, Kwalitee, perl::Critic, etc ... on my modules
> but none of
> them is ran on my tests. tests have a tendency to become a mess, be
> undocumented, etc..
[snip]
I run those sort of things on my tests too... e.g. my Perl Critic
tests does something like:
all_critic_ok( all_perl_files( 'bin', 'inc', 'lib', 't' ) );
Adrian