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?
Asked
Active
Viewed 68 times
2
Anna
- 2,645
- 5
- 25
- 34
2 Answers
6
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/';
Dave Cross
- 68,119
- 3
- 51
- 97
4
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'};
DavidO
- 13,812
- 3
- 38
- 66