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?
How can I pass prove (Test::More) an argument, e.g. an API URL?
92 Views Asked by Anna At
2
There are 2 best solutions below
0
On
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.comwould run
t/mytest.twith 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'};
Maybe set a default URL in the test program but allow it to be overridden by an environment variable.