views:

33

answers:

2

Right now when i do something like this:

use strict;
use warnings;

package My::Test;
use parent 'Test::Class';
use Test::More;

sub overrides_basic : Tests {
    ok( 1, "works" ); ok( 1, "works" );
}
sub overrides_no_profile : Tests {
    ok( 2, "works" ); ok( 2, "works" );
}
__PACKAGE__->runtests;
1;

The output is this:

ok 1 - works
ok 2 - works
ok 3 - works
ok 4 - works
1..4

This is not very nice.

However, if i do this:

use strict;
use warnings;

package My::Test;
use parent 'Test::Class';
use Test::More;

sub overrides_basic : Tests {
    subtest 'overrides_basic' => sub {
        ok( 1, "works" ); ok( 1, "works" );
    };
}
sub overrides_no_profile : Tests {
    subtest 'overrides_no_profile' => sub {
        ok( 2, "works" ); ok( 2, "works" );
    };
}
__PACKAGE__->runtests;
1;

The output is nicer and more desirable, like this:

    ok 1 - works
    ok 2 - works
    1..2
ok 1 - overrides_basic
    ok 1 - works
    ok 2 - works
    1..2
ok 2 - overrides_no_profile
1..2

The problem here is that this is a lot of unnecessary typing work to do. So for now, i'll just be sub-classing Test::Class to redefine the Tests sub-arg.

However I am wondering if there already is a simple solution for this that i was unable to find.

+3  A: 

After some research i found this does not seem to be supported at all, so, here's a module i just wrote to solve this:

Test::Class::TestGroup

Mithaldu
+1  A: 

Test::Class is going to be updated to support subtests when I get the spare tuits :-)

An initial draft was done when we introduced them at the 2009 qa-hackathon. Just need to find the time to tidy up and merge in with the latest fixes.

adrianh
Wow, thanks for the answer and good luck on implementing it. :)
Mithaldu