Moving Variables in Perl Test :: More.t file

Is there a way for area variables for Test :: More tests in a .t file? For instance:

# 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 ... 

I am looking for a way to discretely manage individual tests in a .t file, so no conflicts / errors are introduced if variable names are reused between tests.

Sal.

+4
source share
2 answers

To extend mirod's correct answer: you can use variable regions with curly braces, as with any Perl program, however you can do it even further. Test :: More has the concept of a subtest in which you define a subref that contains one or more tests that run together (and, of course, creating a scope in the process).

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

Wrap each test in braces:

 { # test1 ... } { # test 2 ... } 
+5
source

Source: https://habr.com/ru/post/1496315/


All Articles