I have being taking a look at some modules of perl, and I have seen it is kind of a standard to have a lot of tests under a folder t
whith the extension .t
.
Those scripts can be executed directly with perl <test>.t
.
I want to do a little framework to test one application. I want to have many simple tests. And then a main script which calls this tests to validate everything at once, but still being able to run the little tests individually without having to disable manually the other tests in the main script.
My question is how should I do this calling? As suggested in How do I run a Perl script from within a Perl script? this interprocess communication should be avoided and instead use modules but that would make not possible to run the tests directly.
My guess was to do something as follows. In an example where I need to give some parameters in a selenium script This is the folder structure:
├── main_script.pl
└── t
├── 00-Test_1.t
├── 01-Test_2.t
├── 02-Test_3.t
└── 03-Test_4.t
And I would call them like this:
system($^X, "./t/00-Test_1.t", "-b $browser", "-s $server", "-d $debug");
my $results = capture($^X, "./t/00-Test_1.t", "-b $browser", "-s $server", "-d $debug";
$log->info("Result is $results");
And each test would have something like this:
my ($browser, $server, $debug);
GetOptions(
'debug|d' => \$debug,
'debug|d' => \$trace,
'trace|t' => \$browser,
'server|s=s' => \$server,
) or die "[ERROR] Invalid options passed to $0\n";
Is this a correct approach or is there something more appropiate for doing this using modules?