No, see, I want to establish a set_up/tear_down that are exectuted not once for each test, but a set_up that is run once before the first test is run, and a teat_down that is run once after the last test is run.

Test::Unit::Setup is a decorator for suites, not test cases, so you'll need to do something like this:

package My::TestCase; use base qw(Test::Unit::TestCase); use Test::Unit::TestSuite; sub test_the_first { my $self = shift; $self->assert( 1, 'first' ); } sub test_the_second { my $self = shift; $self->assert( 1, 'second' ); } sub suite { return MySuiteSetup->new( Test::Unit::TestSuite->new( __PACKAGE__ ) ); } package MySuiteSetup; use base qw( Test::Unit::Setup ); sub set_up { warn "before all tests\n"; } sub tear_down { warn "after all tests\n"; }
Our group is already pretty heavily invested in Test::Unit, but I can ask the other guys what they think of Test::Class

Just as a point of comparison, this would be how you would do it in Test::Class.

package My::Test; use base qw( Test::Class ); use Test::More; sub before :Test( startup ) { warn "before all tests\n"; }; sub first :Test { pass }; sub second :Test { pass }; sub after :Test( shutdown ) { warn "after all tests\n"; };

You might also be interested in PerlUnit@yahoogroups.com, a mailing list dedicated to Test::Unit. Traffic has been sparse though...


In reply to Re^3: How do I use Test::Unit::Setup? by adrianh
in thread How do I use Test::Unit::Setup? by DrWhy

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.