Why use Perl for Testing
The question - Why use Perl for Testing came up in the middle of this thread http://firstname.lastname@example.org/msg10305.html on the perl-qa mailing list. Let's try to collect the wisdom here. I started to copy paste and change some of the responses.
Why use perl for testing? Of course all others languages are used for testing this and that.. What excels perl to be used for testing. Obviusly it has powerfull regex, and datahandling capabilities... But besides that.. Why would anyone want to use perl? :)
- The Perl community has a highly evolved and culturally integrated attitude to testing - so even if you're not programming in Perl you
may find some of the tools (both software and conceptual) useful.
- Programs can talk to each other and there's no reason that they all need to be written in Perl. For example the MediaWiki team use
Test::Harness (Perl) with a PHP testing module to run their PHP tests.
Perl uses TAP, the Test Anything Protocol. In most other testing systems the test script also determines whether the test passes or fails and it also displays that fact. This means the thing you're testing is tied to the testing system.
TAP instead follows the Unix philosophy of pipes. A harness (usually Test::Harness) runs a series of programs which output TAP, a simple textual protocol.
1..3 ok 1 ok 2 not ok 3
That is, "I'm going to run 3 tests. The first one passed. The second one passed. The third one failed." The harness parses this and displays the results.
This separation means you have maximum flexibility in how you write your tests. You're not locked down to one set of test functions, you can import piles and piles from CPAN and even write your own. You can even get XUnit style test methods (see Test::Class).
With Test::Harness 3 you can define special behaviors for various test files. The power of this is that the test scripts can be written in anything, doesn't have to be Perl. There are TAP libraries in several languages and because the basic protocol is so simple they're simple to implement. I've seem places write TAP tests in C, shell, PHP and Java in the same test suite. Even running their .html files as "tests" by instructing the harness to run them through an HTML syntax validator.
The downside is there's no pretty GUIs for TAP, but the potential exists. It's a simple matter of programing. The upside is that when a TAP GUI is created it will work with all existing TAP tests.