Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Sharing data between tests?

by ghenry (Vicar)
on Jan 31, 2012 at 21:06 UTC ( #951068=perlquestion: print w/replies, xml ) Need Help??
ghenry has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I've almost completed the first version of the SureVoIP RESTful hypermedia API and wanted some advice on sharing data between separate tests.

I'm working on the create customer method (POST to /customers) and once I've returned "201 Created" I'll have the Location of the new customer resource. How should I save this and use it in all my other tests? Config::Tiny? Storable?

What do you recommend? I can't see anything apart from Temp databases in Perl Testing: A Developer's Notebook and nothing in Test::More

I'm using Catalyst, Catalyst::Controller::REST, PostgreSQL and DBIx::Class

Thanks, Gavin.

Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a Just ask!!!

Replies are listed 'Best First'.
Re: Sharing data between tests?
by chromatic (Archbishop) on Jan 31, 2012 at 21:24 UTC

    I use fixtures with a temporary database (DBICx::TestDatabase). I usually create a module under t/lib/ which performs bulk inserts of the relevant data.

    I don't create data in one test and use it in another because that implies an ordering between tests that can be fragile, and works against test parallelism.

    If you need more details, let me know; I can post code when I have more time.

      Thanks. Maybe I should just do the create user in one test and verify it's there and then use a known user in all the other tests.

      They don't have to be ordered, but it would be good to check the freshly created user and do everything the API allows using said user.

      It's things like update their own info, order telephone numbers, send a fax, send an SMS, email to fax, make a call etc. etc.

      Walking the road to enlightenment... I found a penguin and a camel on the way.....
      Fancy a Just ask!!!
        Maybe I should just do the create user in one test and verify it's there and then use a known user in all the other tests.

        That's what I do. Many of my hardcoded expectations eventually bite me later.

Re: Sharing data between tests?
by Util (Priest) on Jan 31, 2012 at 21:31 UTC

    Unless efficiency is truly critical, I would avoid Storable, along with any other binary format. Test suites (both code and data) are a form of documentation, and should be in a human-readable format.

    Even when the datasets are generated during one test, and (normally) deleted later toward the end of the test suite, a human-readable (and editable) datastore will save you much frustration when diagnosing a failed test.

    I have used Data::Dumper, YAML, and Config::Tiny on different projects. I think that Config::Tiny is better suited to true config files that a non-programmer will be editing. If I was saving shared test data today, JSON::XS would be my first choice.

    Note that you need not just bundle the data. You can also bundle helper subroutines, that might simply return the data, or might *generate* the data in some expanded format that your tests can easily use, rather than whatever compact format the data might actually live in.

Re: Sharing data between tests?
by JavaFan (Canon) on Jan 31, 2012 at 21:46 UTC
    If it's just a single URL? I'd write it in a plain text file. Why bother with a framework if all you need is a single piece of data?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://951068]
Approved by Perlbotics
[ambrus]: 1nickt: for some reason, these days they call every computer "gaming", even ones that gamers wouldn't buy. I've bought a keyboard that was labelled "gamer", despite that it has hard springs and seems to be way better for typing than for gaming;
[1nickt]: I though the gamers like that because they bash the keys so hard.
[ambrus]: and I've seen motherboards with no fast expansion ports for a video card but built-in hardware RAID advertized as "gaming".
LanX has a shaming laptop
[ambrus]: 1nickt: my impression is that the gamers like the softer springs, because fast reaction time is more important to them then feedback from keypresses to recognize typos.
[1nickt]: Ah, I see. I did read some gamer mag reviews, and yes, they lamented the fact that laptops with no discrete video card are sold as "gaming" hardware.
[1nickt]: But, they do have red keyboard backlighting! And gargoyles on the front, or words like "Maxxx" here and there. They know their demographic!
[1nickt]: True gamers don;t buy Dells, HPs, or Lenovos, I think ;-)
[ambrus]: The keyboard I bought doesn't have backlighting. I specifically had to select for that, because so many keyboards these days have lights. Why would I want lights in the keyboard? I want lights in the room, such as on the ceiling, not in the keyboard.
choroba has a small USB lamp

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2017-03-27 13:47 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.