Perl Best Practices
18.3. Test Suites
Standardize your test suites with Test::Harness. Once you've written your tests using one of the Test:: modules, in a series of .t files in the t/ subdirectory (as described in the previous guideline, "Modular Testing"), you can use the Test::Harness module to make it easier to run all the test files in your test suite. The module is specifically designed to understand and summarize the output format used by Test::Simple and Test::More. It comes with an invaluable utility program named prove, which makes it trivially easy to run all the tests in your /t directory and have the results summarized for you: > prove -r t/articles........ok t/inflections.....NOK 3# Failed test (inflections.t at line 21) t/inflections.....NOK 6# Failed test (inflections.t at line 21) t/inflections.....ok 8/0# Looks like you failed 2 tests of 8. t/inflections.....dubious t/other/conjunctions....ok t/verbs/participles.....ok Failed 1/4 test scripts, 75.00% okay. 2/119 subtests failed, 98.32% okay.
The -r option tells prove to recursively search through subdirectories looking for .t files to test. You can also specify precisely where to look for tests by explicitly telling prove the directory or file: > prove t/other t/other/conjunctions....ok All tests successful.
The utility has many other options that allow you to preview which tests will be run (without actually running them), change the file extension that is searched for, run tests in a random order (to catch any order dependencies), run tests in taint mode (see the perlsec manpage), or see the individual results of every test rather than just a summary. Using a standard testing setup and a coordinating utility like this, it's trivial to regression test each modification you make to a module or application. Every time you modify the source of your module or application, you simply type prove -r. Instantly, you can see whether your modification fixed what it was supposed to, and whether that fix broke anything else. |