chrestomanci has asked for the wisdom of the Perl Monks concerning the following question:
Greetings brothers.
I am currently writing a test suite for a DBIx::Class based project using Test::Class. I am having trouble with the order that Test::Class calls the startup methods I have defined.
package Test::Setup; use base 'Test::Class'; use Test::Most; # Pulls in strict, warnings, T::More, T::Exception +etc. use Schema; # The base of my DBIx::Class classes. sub db_connect : Test(startup) { my $self = shift; my $schema = Schema->connect('dbi:SQLite:dbname=:memory:'); $schema->deploy(); $self->{'schema'} = $schema; }; package Test::Schema::Result::Organisation; use base 'Test::Setup'; use Test::Most; # This does not work! # I expected it to get called after the parent class startup method, b +ut instead it gets called first, # before the startup method in Test::Setup so there is no DB connectio +n and the schema is not defined. # # Test::Schema::Result::Organisation::create_organisation sub create_organisation : Test(startup) { my $self = shift; my $schema = $self->{'schema'}; $self->{'Organisation'} = $schema->resultset('Organisation')->create +({ 'name' => 'BigCheeseIndustries', 'description' => 'Test Organisation for the test suite', }); return; };
In the example above, the create_organisation method gets called before the db_connect method that it depends on. I had expected Test::Class to respect the inheritance order of my test classes, and call the parent startup methods before the children, but that does not appear to be the case.
I have read in the Test::Class docs, that startup methods are run in alphabetical order, and I am able to fix the order by prefixing the method names with A_, B_ etc, but this feels like a crude hack. Is there a smarter way?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Order of startup methods with Test::Class
by Old_Gray_Bear (Bishop) on Aug 31, 2011 at 11:41 UTC | |
Re: Order of startup methods with Test::Class
by Ovid (Cardinal) on Oct 09, 2011 at 15:02 UTC | |
by chrestomanci (Priest) on Oct 09, 2011 at 20:21 UTC | |
by Ovid (Cardinal) on Oct 10, 2011 at 19:30 UTC |