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":



  • 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, details, 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, summary, 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.