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?
In reply to Order of startup methods with Test::Class by chrestomanci
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |