Parts of my test suite relies on an API URL. Sometimes I want to run my test using another URL. Is there a way to pass this argument to prove
, or would I need to edit the file that defined the API URL?
CodePudding user response:
Maybe set a default URL in the test program but allow it to be overridden by an environment variable.
my $url = $ENV{MY_TEST_URL} // 'http://api.example.com/';
CodePudding user response:
The documentation for prove
(perldoc prove
) contains the following:
Arguments to Tests It is possible to supply arguments to tests. To do so separate them from prove's own arguments with the arisdottle, '
::
'. For exampleprove -v t/mytest.t :: --url http://example.com
would run
t/mytest.t
with the options '--url http://example.com
'. When running multiple tests they will each receive the same arguments.
Thus, the parts after the ::
will appear in @ARGV
for the test script. I prefer offering a combination of options for passing args. For example:
my $url = $ARGV[0] // $ENV{'TEST_URL'};