简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM