The best idea i've come up with, right now, is using a similar technique to the one used by Damian Conway in the Perl6::Slurp tests with Test::More, and extend it to Test::Class. Here is what he does, to avoid duplicating the test name (Test::Class does this automatically, with the subroutine name) :

my $desc; sub TEST { $desc = $_[0] }; TEST "can't slurp in void context"; # your test here ok 1, $desc;

What i did to extend it to groups of tests in Test::Class, is to use Tests() groups, and having the TEST subroutine declare a test description for each test, and append the subroutine name at the beginning. Like this :

use strict; use warnings; #comment before releasing use Perl6::Say; use Time::TimeTick; # TEST : # my function for displaying information about each test, # in a Test::Class Test subroutine with several tests my $desc; sub TEST { my $test_name = $_[0]; my $caller_func = (caller(1))[3]; # the subroutine full name my $test_group = (split('::', $caller_func))[-1]; # only the subroutine name $test_group =~ s/_/ /g; # replace underscores by spaces $desc = "$test_group $test_name"; }; use base qw(Test::Class); use Test::More 0.98; __PACKAGE__->runtests unless caller; sub A_Fruit__On_a_branch : Tests(3) { TEST "Grows"; ok 1, $desc; TEST "Can rot"; ok 1, $desc; TEST "Can fall"; ok 1, $desc; }; sub A_Fruit__On_the_floor__Rots : Test { ok 1; } done_testing(); 1;
The output is
1..4 ok 1 - A Fruit On a branch Grows ok 2 - A Fruit On a branch Can rot ok 3 - A Fruit On a branch Can fall ok 4 - A Fruit On the floor Rots

Conclusion :
This does part of what i want : my (one level) nested structure enables me to avoid duplication in test names.
And it doesn't do some of the things that i want (and that Test::Spec does - just check the synopsis) :
- more than one level nested structure.
- different "before" setup functions in different test groups.
- nested "before" setup functions : "The setup work done in each before block cascades from one level to the next"

PS : i just realized, i have no idea to which extent this would work with the Test::Class inheritance process. I guess i'll have to try.

And same thing if i implemented a bit of Test::Spec into Test::Class (i thought of a possible not-too-hard way to implement "describe" and "before each"), i'm not sure that it would work with inheritance. You can inherit a subroutine, but how do you inherit it's context ("describe" and "before each" nested structure) ?


In reply to Re^2: Test::Class with Test::Spec's sugar ? by mascip
in thread Test::Class with Test::Spec's sugar ? by mascip

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.