Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

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

I'm having a hard time understanding how I can test an application the supports more than one type of data backend.

For example, I have an app that can save its data in both a plaintext backend, and an SQL backend.

(Say) I have a module called, "App::Backend" that holds all the shared subroutines/methods, and two other modules, called, "App::Backend::PlainText" and App::Backend::SQL" which hold different versions of the same methods - anything that can't be shared.

App::Backend looks like this:

package App::Backend; use App::Config; use base "App::Backend::App::$Config::Backend_Type"; sub shared_method_1 { my $self = shift; #.... } # ... the rest of the module... 1;

(App::Config just holds the configuration variables)

Say, App::Backend::SQL has a method, like this:

sub type { my $self = shift; return 'SQL'; }

and App::Backend::PlainText has a method, like this:

sub type { my $self = shift; return 'PlainText'; }

My test file looks something like this:

#!/usr/bin/perl use Test::More qw(no_plan); for(qw(PlainText SQL){ require App:Config; $App::Config::Backend_Type = $_; require App::Backend; ok($App::Config::Backend_Type eq $_); my $backend = App::Backend; ok($backend->type eq $_); # Wrong! }

It's wrong, because App::Backend is never refreshed and the, "use base" line is never called again. I've tried deleting it from %INC, but that doesn't seem to do the trick (and seems wholly wrong)

Changing the backend like this isn't something I ever want to do in code, but in testing, it's real useful to make sure every backend is checking out on the tests.

The only thing I can think of, is to make a test file for each backend, that are exactly the same, except that the $App::Config::Backend_Type is set to a different thing, before I call App::Backend->new;

Any other ideas? What do you all do to test the various backends in your app? Is my, "use base" way of doing things not the best? I'm starting to look at other packages, like CGI::Session on CPAN - looks like there's just different test files for each backend. Sigh.

 

-justin simoni
skazat me


In reply 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 romping around the Monastery: (6)
As of 2024-04-24 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found