Brett Sanger wrote:
I have some related tests.  For example, to test the account management
of our LDAP administration tools on the website, I have a test to create
an account, test various edit options, then delete the account.  (This
is testing the create and delete as well, so I don't want to use an
existing account).  This means that I either write a very large,
monolithic .t file which reduces my ability to testing single functions
of the interface, or I write separate .t files for each function.  In
the latter case, I have to either be sure to run the create in the
beginning and the delete at the end (see prove and order of tests at the
start of this email) or I have to copy the create and delete code into
each tests, making maintenance harder.  Is there a common way to
modularize code in test files?  Is this just a "do" call?

You might look at Test::Class, which has some nice features for handling repetitive setup/teardown needs.

A more manual approach is to put your common testing code in its own module and "use" that in each of your test scripts. If you're using prove, you should be able to create t/Common.pm, define "package t::Common;" in that file, and then "use t::Common" in your tests scripts. (This assume that you run your tests from the directory above "t/" so that "t::Common" finds your module.)

Regards,
David Golden

Reply via email to