Alexander Bird
Alexander Bird

Reputation: 40639

How do I use the Test::Unit::TestCase Perl CPAN module?

I have the following file:

#!/usr/bin/perl
use Test::Unit::TestCase;
$self->assert(1)

and when I run test.pl I get the following:

Can't call method "assert" on an undefined value at ./parse.pl line 3.

I ran sudo perl -MCPAN -e 'install Test::Unit' and the module seemed to be installed correctly (especially since I get no error on the use statement), but I don't know how to actually use the module.

Upvotes: 1

Views: 540

Answers (1)

btilly
btilly

Reputation: 46408

Did you try copying the code sample from the documentation? (see perldoc Test::Unit::TestCase on the command line.)

Your first problem that you are getting warnings about is that $self has not been initialized. A second problem is that you are not using strict, which would have given you a clearer warning. A third problem is that you are not inheriting from the module. The code sample in the documentation will solve the first and third problems, and the second is something that should become a habit.

Upvotes: 4

Related Questions