views:

1195

answers:

7

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.

Edit

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?

+15  A: 

Test::More is the most commonly used way to write tests in Perl AFAIK. The program prove can be used to run the tests.

Leon Timmermans
+5  A: 

If you are used to xUnit-style frameworks, you'll probably want to take a look at Test::Class. You'll use in alongside the already mentioned Test::More. If you need some guidance, there is probably quite a bit that is googleable... I have a slideshow that might serve as a decent reference. It provides a Test::More and then a Test::More+Test::Class TDD example.

Josh McAdams
+18  A: 

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

tvanfosson
TDD with Perl - Episode 1 http://www.lancewicks.com/blog/index.php?entry=entry081011-094937
converter42
btw is there a way to add vi auto syntax for t files?
melaos
+2  A: 

I recommend Test-Driven Development by Grant McLean.

Philip Durbin
+1  A: 

There's also An Introduction to Test Driven Development Using Perl by Grant McLean.

+1  A: 

A human readable test framework is Aslak Hellesøy's Cucumber. It was written for Ruby and has become very popular for both developers and less tech folks.

I have recently put together a Perl version of this called cucumber.pl that you might enjoy using. I use this alongside the aforementioned Test::More but any of the test modules work pretty well alongside it.

Stephen Hardisty
A: 

The test suite for Catalyst::Runtime is pretty comprehensive, and includes using Apache::Test to test the framework in mod_perl in a couple of the t/optional* scripts. For actual web app testing MVC style, the tests MoJoMojo aren't bad for a set of web app tests either.

singingfish