简体   繁体   English

如何使用Test :: Unit :: TestCase Perl CPAN模块?

[英]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: 当我运行test.pl我得到以下内容:

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. 我运行sudo perl -MCPAN -e 'install Test::Unit'并且模块似乎安装正确(特别是因为我在use语句中没有出现错误),但我不知道如何实际使用该模块。

Did you try copying the code sample from the documentation ? 您是否尝试从文档中复制代码示例? (see perldoc Test::Unit::TestCase on the command line.) (请参阅命令行上的perldoc Test::Unit::TestCase 。)

Your first problem that you are getting warnings about is that $self has not been initialized. 您收到警告的第一个问题是$self尚未初始化。 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. 文档中的代码示例将解决第一个和第三个问题,第二个问题应该成为习惯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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