http://www.perlmonks.org?node_id=1072954


in reply to Looking for help for unit tests and code coverage on an existing perl script

I would extract a module from your script and unit test the module directly via Test::More and the prove command. I like to keep my script mainlines as short as is practicable, with all the heavy lifting done in (unit-tested) module/s. There are many examples of this general approach on the CPAN; see, for example, the perltidy command, part of the Perl-Tidy distribution and the perlcritic command, part of the Perl-Critic distribution.

As an alternative, and perhaps a bit less work, you could re-structure your script as a "modulino", that is, a script that can masquerade as a module for ease of testing. This approach is described at:

... though modulinos are too sneaky/clever for my tastes ("scripts should use modules, not pretend to be modules").

References Added Later

PM Nodes:

Updated: Many extra references were added long after the original reply was made.