Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (6)
    As of 2018-03-19 00:10 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (231 votes). Check out past polls.