This is my setup for a generic project:

source bin lib t data

The lib directory (and below) contains the source files (for My::Module::Name in My/Module/Name.pm).

The t directory contains all the test files, one for each class (e.g. My-Module-Name.t). Sometimes there are extra files for some classes if some aspects of it need more tests (e.g. My-Module-Name-convert.t). I don't care about the order of tests being run; if something breaks, it's usually easy to figure out the root cause of the breakage.

The t/data directory contains data used by the tests.

Basic classes are easily tested by themselves. Other classes have dependencies, and then it becomes necessary to set up an environment for them to work. I do this in each file that needs it. Sometimes it becomes very repetitive, and it may be a good idea to refactor the setup test code into a class (e.g. SetupFoo.pm) which I put in the t directory and use from the .t files.

For complicated chains of depdent classes or external resources like web server access or time, I find it useful to fake it with Test::MockObject. WWW::Mechanize::Cached is also useful to fake web sites.

Well, that's how I do it.

/J


In reply to Re: How to structure tests that span several modules by jplindstrom
in thread How to structure tests that span several modules by talexb

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.