有没有办法在 .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/