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

发布于 2024-10-17 06:36:38 字数 373 浏览 4 评论 0原文

我有以下文件:

#!/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

有木有妳兜一样 2024-10-24 06:36:38

您是否尝试从文档复制代码示例? (请参阅命令行上的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文