Skip Menu |
 

This queue is for tickets about the Test-Class CPAN distribution.

Report information
The Basics
Id: 39266
Status: resolved
Priority: 0/
Queue: Test-Class

People
Owner: Nobody in particular
Requestors: ADIE [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Test::Class with Package::Alias
Download (untitled) / with headers
text/plain 192b
Some kind of problem. See http://annocpan.org/~ADIE/Test-Class-0.30/lib/Test/Class.pm#note_2038 ... of course now way to locate the person to figure out what is actually going on.... sigh...
Download (untitled) / with headers
text/plain 1.4k
Hello, Thanks for the terrific test library! I'm seeing startup and shutdown methods being ran more than once like in the description at AnnoCPAN, but it looks unrelated to Package::Alias. To me it seems to have to do with inheritance. Put the attached file in ./lib/Example/Test.pm When ran as suggested in the synopsis, it appears that the startup and teardown methods are ran for each test method (and even then not in the order I would "expect"): $ perl -Ilib -MExample::Test -e 'Test::Class->runtests' # running before tests 1..5 ok 1 - pop = 2 ok 2 - pop = 1 ok 3 - array empty ok 4 - pop = undef # array = () after test(s) ok 5 - push worked # array = (1 2 3) after test(s) # running after tests # running before tests # running after tests Notice how at the bottom of the output it appears there are superfluous runs of the startup and teardown methods. But when ->runtests is called via Example::Class, it seems to work properly: $ perl -Ilib -MExample::Test -e 'Example::Test->runtests' # running before tests 1..5 ok 1 - pop = 2 ok 2 - pop = 1 ok 3 - array empty ok 4 - pop = undef # array = () after test(s) ok 5 - push worked # array = (1 2 3) after test(s) # running after tests If you despense with the Example::Base and put the startup and teardown methods in Example::Test, Test::Class->runtests seems to do the right thing. Thanks again, Todd W.
Download Test.pm
text/x-perl 1k
use warnings; use strict; package Example::Base; use base qw(Test::Class); use Test::More; sub db_connect : Test(startup) { diag("running before tests"); }; sub db_disconnect : Test(shutdown) { diag("running after tests"); }; package Example::Test; use base qw(Example::Base); use Test::More; # setup methods are run before every test method. sub make_fixture : Test(setup) { my $array = [1, 2]; shift->{test_array} = $array; }; # a test method that runs 1 test sub test_push : Test { my $array = shift->{test_array}; push @$array, 3; is_deeply($array, [1, 2, 3], 'push worked'); }; # a test method that runs 4 tests sub test_pop : Test(4) { my $array = shift->{test_array}; is(pop @$array, 2, 'pop = 2'); is(pop @$array, 1, 'pop = 1'); is_deeply($array, [], 'array empty'); is(pop @$array, undef, 'pop = undef'); }; # teardown methods are run after every test method. sub teardown : Test(teardown) { my $array = shift->{test_array}; diag("array = (@$array) after test(s)"); }; 1;
Download (untitled) / with headers
text/plain 375b
Very belated response :-) The extra startup/shutdown methods were caused by the base class. Currently Test::Class runs the control methods for all classes unless SKIP_CLASS is set - even if there are no test methods to be run. This is now fixed in git, and will be in the next release. In the mean time you can always set SKIP_CLASS for the base class. Cheers, Adrian


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.