perl - Perl Test::More .t 文件中的范围变量

标签 perl unit-testing

有没有办法在 .t 文件中为 Test::More 测试范围变量?例如:

# 1st Test
$gotResult = $myObject->runMethod1();
$expectedResult = "value1";
is($gotResult, $expectedResult, "validate runMethod1()");

#2nd Test
$gotResult = $myObject->runMethod2();
$expectedResult = "value2";
is($gotResult, $expectedResult, "validate runMethod2()");

#3rd Test
...

我正在寻找一种方法来离散管理 .t 文件中的各个测试,因此如果在测试之间重用变量名称,则不会引入冲突/错误。

萨尔。

最佳答案

为了扩展 mirod 的正确答案:您可以像使用任何 Perl 程序一样使用大括号来限定变量的范围,但是您可以更进一步。 Test::More 有一个子测试的概念,您可以在其中定义一个子引用,其中包含一个或多个一起运行的测试(当然还可以在过程中创建一个范围)。

subtest 'Subtest description here' => sub {
  # do some setup, then do some tests
  ok 1, 'the simplest test';
};

关于perl - Perl Test::More .t 文件中的范围变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18162242/

相关文章:

php - 编辑nmap2db.pl(更改数据库更新语句)

xml - 为什么我在使用 Perl 的 XML::Simple 时会收到 "Out of memory"错误?

c# - 在 AutoFixture 中注入(inject)接口(interface)和实现

c++ - 使用 Boost 和 Eclipse 进行单元测试

Perl 执行命令,捕获并显示输出

perl - 进行替换直到某些条件为真

perl - 将提交评论复制到 Windows 剪贴板

unit-testing - 如何使用 JUnit 测试我的 servlet

swift - Xcode:如果前一个失败则跳过测试

symfony - 使用 phpStorm 在 Symfony 3.2.4 中进行功能测试