如何使用 Test::Unit::TestCase Perl CPAN 模块?
我有以下文件:
#!/usr/bin/perl
use Test::Unit::TestCase;
$self->assert(1)
当我运行 test.pl
时,我得到以下信息:
Can't call method "assert" on an undefined value at ./parse.pl line 3.
我运行了 sudo perl -MCPAN -e 'install Test::Unit'
和模块似乎安装正确(特别是因为我在 use
语句上没有收到错误),但我不知道如何实际使用该模块。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试从文档复制代码示例? (请参阅命令行上的
perldoc Test::Unit::TestCase
。)收到警告的第一个问题是
$self
尚未初始化。第二个问题是您没有使用 strict,这会给您一个更清晰的警告。第三个问题是您没有从模块继承。文档中的代码示例将解决第一个问题和第三个问题,第二个问题应该成为一种习惯。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.