I can offer several thoughts from my own practices -- no claim that any is right (clearly I don't even have a really consistent standard), but one or more of them may resonate for you.
- For a really simple module, all the tests go in one file in the t/ directory
- For utility modules, I tend to break out test scripts somewhat ad hoc to test different types of functionality. (You might think of this as testing 'use cases')
- For a distribution with lots of classes/subclasses, I've generally gone with one test file per module, testing whatever is unique/different about that module
- In one case, with a really complicated object hierarchy, I've set up subdirectories within t/ to mimic my object hierarchy and customized the Build.PL to search t/ recursively.
- If I find myself with a lot of redundant setup code, I create a "TestHelper.pm" module in the t/ directory and have my test scripts load that. (Though I recently learned about Test::Class and think it might be a better approach for that kind of thing.)
Generally, I consider test scripts cheap and don't hesistate to create a new one to test a narrow set of functionality. That said, I try to keep related tests grouped together in one file.
Also, in your core toolkit of Test modules, make sure you look at Test::Exception. I use it so frequently that my default .t template automatically sticks that in along with Test::More. (And if you're doing a lot of floating-point math, you might appreciate my own Test::Number::Delta, too.)
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.