Skip to Content
Advanced Perl Programming, 2nd Edition
book

Advanced Perl Programming, 2nd Edition

by Simon Cozens
June 2005
Intermediate to advanced
298 pages
7h 28m
English
O'Reilly Media, Inc.
Content preview from Advanced Perl Programming, 2nd Edition

Chapter 8. Testing

Every programmer likes writing code, but only a brave and masochistic few actually like writing tests for their code. However, with the rise of XP, Agile programming, and other programming methodologies, it has become more important for programmers to write complete test suites for the code they produce.

Not only that, but thanks to the efforts of the Perl Kwalitee Assurance team, headed by Michael Schwern, there’s a good deal of social pressure for CPAN module writers to come up with thorough automated test plans for their modules.

Thankfully, Schwern and others have also produced a bunch of modules that make producing such test plans relatively painless. We’ll take a look at the more popular and useful modules in this chapter.

Test::Simple

Back in the mists of time, around the late 1990s, test plans were very simple indeed; you had a program that spat out “ok” or “not ok” followed by a test number, and an automated testing harness would go through, run your tests, and pick out the tests that failed.

So, programmers would write test scripts that looked something like this:

    print "1..10\n";

    print (( 1 + 1 =  = 2  ? "": "not "), "ok 1\n");
    print (( 2 + 2 != 7  ? "": "not "), "ok 2\n");
    if (foobar() ) {
        print "ok 3\n";
    } else {
        print "not ok 3\n";
    }
    ...

Then some programmers realized they didn’t want to keep score of the test numbers themselves, so they used a variable instead:

 print "1..10\n"; my $i = 1; print (( 1 + 1 = = 2 ? "": "not "), "ok ", $i++, "\n"); print (( 2 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Perl Programming

Advanced Perl Programming

Sriram Srinivasan
Perl in a Nutshell, 2nd Edition

Perl in a Nutshell, 2nd Edition

Nathan Patwardhan, Ellen Siever, Stephen Spainhour

Publisher Resources

ISBN: 0596004567Errata Page