Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
No such thing as a small change
 
PerlMonks  

Re: Setting up a test db with MakeMaker

by choroba (Abbot)
on Feb 23, 2013 at 09:46 UTC ( #1020293=note: print w/ replies, xml ) Need Help??


in reply to Setting up a test db with MakeMaker

If you need a code to be called from each .t file, what about wrapping it into a module? You can even place it into the t/ directory and just add the following to each .t file:

use TestSetup;
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Setting up a test db with MakeMaker
Download Code
Re^2: Setting up a test db with MakeMaker
by tmharish (Friar) on Feb 23, 2013 at 10:08 UTC
    what about wrapping it into a module? You can even place it into the t/ directory and just add the following to each .t file: use TestSetup;

    Does that work on 5.6?

      Does that work on 5.6?

      Why should it not work? Why don't you try it?

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Why should it not work?

        Because I assumed that this will require BUILD_REQUIRES to be set and the default ExtUtils::MakeMaker version that shipped with 5.6 dint have it.

        Why don't you try it?

        I did and am yet to get it to work ( even on higher versions ) - Will reply once I find a way to get it to work or I give up, meanwhile - Did you?

        Update: I Managed it with a require 't/tests.pm'. I am not sure that thats what choroba meant though.

Re^2: Setting up a test db with MakeMaker
by danmcb (Monk) on Feb 25, 2013 at 14:10 UTC

    indeed, this works fine. Some code for those that are curious:

    in t/test_setup.pm:

    package test_setup; sub setup { # setup your db or whatever here } 1;

    In a test module

    require t::test_setup; test_setup::setup();

    Rather simple in fact. Works fine on 5.10

    UPDATE: in fact - I am using this.

    package test_setup; sub setup { # ... } BEGIN { # must be after the sub definition setup(); $ENV{USE_TEST_DB} = 1; } 1;

    And in my Catalyst MyApp.pm class:

    if ( $ENV{USE_TEST_DB} ) { __PACKAGE__->config( 'Plugin::ConfigLoader' => { file => 'myapp_test +.yml'} ); }

    Now it is only necessary to "use" test_setup.pm. The setup is executed automatically, and the ENV variable causes the Catalyst app to use another config, which in turn connects to the test database in place of the normal development one.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020293]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2014-04-18 14:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (469 votes), past polls