Perl testing

www.perl.org
 

Perl testing

Test, test and test some more.

Testing should be the cornerstone to any development teams processes. Creating automated test suites for Perl projects is assisted by over 400 testing and quality modules available on CPAN. Having an automated test suite gives both developers and project managers confidence in the ability of code to perform according to specification.

Testing has been a central part of the Perl development ethos for many years, the Test Anything Protocol (TAP) was initially developed for Perl (released 1987), and is now available for many languages. There are hundreds of Test:: modules on CPAN which use this protocol, enabling the testing of everything from database queries, to objects and websites. The core Perl language has over 250,000 tests, additionally there are over 250,000 tests for the libraries bundled with it.

The other big advantage of automated test suites is that as functional requirements change and additions are made to the code base (requiring refactoring to avoid duplication), it is far easier to spot knock-on effects of code changes because the test suite (if there is enough code coverage) will highlight any issues.

Code coverage measures how much of the code is tested when the test suite is run, Devel::Cover can provide this metric and report which sections and branches of code are not being tested.

A good place to start is Test::Most which combines most frequently used testing modules, so one only need add specific testing modules such as Test::WWW::Mechanize when testing specific types of functionality (such as a webpages in this instance).

Testing is part of Perl's culture, make it part of yours.

Quotes

  • "Built on the shoulders of giants, Test::Most is a great consolidation of many useful things." - Robbie Bow (reviewing Test::Most)
  • "Probably the only way I'd ever be able to ship a new major version of my program is by using the Test::More module. I went from 0 to 5,000+ tests in a little more than a year." - Justin (reviewing Test::More, including with Test::Most).

Resources:

Article Author

Leo Lapworth