in reply to Re: How do I use Test::Unit::Setup?
in thread How do I use Test::Unit::Setup?

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. If my reading of Test::Unit::Setup are correct this allows you to do this. However, I'm not sure how the Test::Unit::Decorators (Test::Unit::Setup isa Decorator) in relation to Test::Unit::TestCase (or is it supposed to be used with a TestSuite?)

Still needing help with this...

P.S. Our group is already pretty heavily invested in Test::Unit, but I can ask the other guys what they think of Test::Class...

Replies are listed 'Best First'.
Re^3: How do I use Test::Unit::Setup?
by adrianh (Chancellor) on Jul 13, 2004 at 18:46 UTC
    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...

      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;
      Thanks adrianh! This is just the bit I needed to make it come together in my head.