views:

696

answers:

5

I have been doing some OO Perl programming and I was wondering: which is the best way to perform unit tests?

So far I have been using the Test::Simple module to perform tests, but it feels insufficient for what I want.

Can you point me to some nice modules for that?

+11  A: 

Test::More should offer you more bang for your bucks once you get the hang of Test::Simple.

Also you can refer to this previous discussion by yours truly if you want more info: how-can-i-implement-tdd-in-perl

melaos
I'm looking for something for close to JUnit or NUnit with a setup and tear down method etc... got any idea?
mandel
@mandel are you running on winx platform?
melaos
yes I am testing on a Win Server or an XP desktop
mandel
+22  A: 

I'd add my vote to picking up Test::More before going any further in Perl testing. The Perl testing community is fairly well united around the Test Anything Protocol, and you'll want to play around with Test::More to understand how it works and how tools like prove and Test::Harness::Archive can help automate and distribute testing.

If you want to just "jump right in", I think Test::Class provides xTest facilities with a TAP backend. I haven't used it at all (I'm a Test::More person myself), but it's very highly rated.

Gaurav
Great introduction, thanks! I'm used to doing unit tests for python and php, but will be involved in a perl project soon, your post definitely helps me get started :)
warpr
+8  A: 

Judging by your comments on melaos answer, I'd say Test::Class or Test::Unit is what you're looking for.

Leon Timmermans
+2  A: 

Simple test example:

#!/usr/bin/perl -w

use strict;
use warnings 'all';
use Test::More plan => 4;  # or use Test::More 'no_plan';

use_ok('My::Module', 'Loaded My::Module');
ok( my $obj = My::Module->new(), 'Can create instance of My::Module');

ok( $obj->value('hello'), 'Set value to hello' );
is( $obj->value => 'hello', 'value is still hello');
JDrago
It will not pass, because you only have 4 tests and you expect 5 ;-)
Leon Timmermans
Fixed - thanks for pointing that one out :)
JDrago
+1  A: 

Test::Class usage you can see in this example.

Hynek -Pichi- Vychodil