Perl Testing

Ian Langworth, Chromatic

Mentioned 3

Looks at the Perl test tools and offers a series of exercises that cover such topics as bundling test suites, testing databases, and testing Web sites and projects.

More on

Mentioned in questions and answers.

We're using mod_perl to produce data in XML and later to be converted into HTML via XSLT, and the database is in MySQL. Our OS is Unix.

So I've been reading about how cool and powerful TDD is in .NET, Java with all the available frameworks. I've even tested NUnit before and I kind of like it. You can write the test once and use it pretty much forever.

I was wondering if there is an easy way to implement TDD for our case too with Perl?

What I want to do is to have some automated way to manage my unit test, and to be able to easily run the unit test with just one click or something.


I've found this chapter on TDD to be very useful as well as helping me design the test, and best of all it's free :)

And if you can afford it then get this book too: Perl Testing: a developer's notebook. It's really good in the sense that it break down into all the potential stuff that we need to do and it's in a tutorial based format.

Added a Perl testing reference card here.

So now I'm eager to look for some good resources, .pm, open source Perl projects which I can use to better learn how to write unit tests, etc. Can anyone recommend some here?

These might be helpful...

Test Driven Development with Perl in Vim

TDD with Perl - Episode 1

TDD with Perl - Episode 2 - Getting Started

TDD with Perl - Episode 3 (whenever Lance gets around to writing it)

Testing / Perl 5 Wiki -- especially the bit on mock objects and the further information and other links sections (seems to be defunct)

What frameworks and tools would you recommend for unit-testing and mock objects in Perl?

I have an existing Perl application, that mainly does database access, reading and writing files. The application is basically a batch job type of application, it reads in bunch of stuff from files and database and writes a bunch of new files and some stuff to database.

The application currently does not have any unit-test, but I'd like refactor application to have good unit tests.

What frameworks and tools would you recommend for unit-testing and mocking objects? For example something similar to Hamcrest and JMock of Java?

Also, are there any good BDD (Behaviour Driven Development) based testing frameworks for Perl?

It is not a framework, but one of the best testing books is the excellent Perl Testing: A Developer's Notebook which also has recommendations of test frameworks for Perl, e.g. Test::More.

Do you have any strategies for retrofitting unit tests onto a code base that currently has no unit tests ?

If ever you are trying to add unit tests to old perl code I strongly recommend

Perl Testing: A Developer's Notebook by Ian Langworth and chromatic.

It has some very nice trick on testing legacy and "untestable" code.