Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hey everyone,

I didn't find a very good answer to my seeking at:

http://perlmonks.org/?node_id=618404

But did come up with an OK ideas that's not too too much playing with dragons.

To recap: I'm trying to make some automated tests for an app that has different options for saving information in the backend.

In my perlcode, these different backends are put together by having a module that holds the shared methods to the object that represents whatever I need the backend for, and then separate modules that hold the backend-centric methods for each of the backends.

the problem with testing these types of backends, is that the backend-centric methods are added at compile time not runtime, since my module that holds the shared methods loads the backend-specific stuff with a:

use base qw(App::Backend::ThisBackend);

Type call.

So, in my testing suite, I now have a few files, instead of one for this specific part of the program.

One is called, "backend.pl" (or, whatever)

And then a test file for each of the different backends.

Those test files basically look like the following. This first example is for a backend that doesn't need anything to be setup, so we just explicitly set the type of backend we're trying to test, in this case a Berkeley DB-type backend:

#!/usr/bin/perl -w use strict; use Test::More qw(no_plan); use App::Config; use App::Config::Backend_Type = 'SQL'; do "t/backend.pl";

Since my backends also use the App::Config and App::Config is in the %INC hash, it won't get imported again, and the variable will be set for them, by this test file.

This is the only part where I'm playing with dragons, since it's not *really* my policy or suggestion that you allow your app to arbitrarily set program global configuration variables, but it does come in handy.

To activate the different backends, I can just add whatever I need to make these different backends work in these test files. For example:

#!/usr/bin/perl -w use strict; use Test::More qw(no_plan); use App::Config; use App::Config::Backend_Type = 'SQL'; require test_helper_utils; test_helper_utils::create_SQL_db(); do "t/backend.pl"; test_helper_utils::destroy_SQL_db();

So basically, the actual tests are imported with do() and the test files themselves just set up the environment.

Since the backends basically have the same API, the tests are the same. Testing all the backends makes sure the different implementations don't get out of sync with each other. This will hopefully stop me from getting so many headaches in the future :)

So that was my solution. Perhaps it could be used as a starting point/pattern for someone else,

Crits?

 

-justin simoni
skazat me


In reply to Followup to: How to test different back ends? by skazat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-28 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found