Is it somehow possible to pass values to NUnit tests via the command line?
My tests use a certain URL. I have different instances of my code at different URLs and would like to specify the URL via the command line. File App.config
is not an option, because I want to run the tests for different URLs via a batch file.
I had a similar issue. The answer of Achim put me on the right track, and for other readers:
Create a file, like
example.nunit
, like this:Next when you want to run it for a certain configuration you execute it like this:
More information about the format of the NUnit file is in NUnit Project XML Format.
More information about command-line arguments is in http://www.nunit.org/index.php?p=consoleCommandLine&r=2.2.5
Use an environment variable to pass the information.
Use
set
from the command-line or<setenv>
from NAnt. Then read the value usingEnvironment.GetEnvironmentVariable()
.There seems to be no solution at the moment. The best option is to use NUnit project files, modify settings there and pass the solution file to the runner.
NUnit 3 now allows passing parameters. Here is the usage
From the documentation
Here's how you can access the parameter through code: