Seems like a pretty trivial question, but to my surprise I found no mention of this on the web.
I've got an Nunit test project (that someone else wrote and I don't want to change too much), that I need to debug. These tests depend on environment variables that they read using Environment.GetEnvironmentVariable
.
My question is: is there a way I can pass environment variables when debugging tests in Visual Studio?
I know I can pass environment variables when I debug an executable project through Project Properties->Debug, but this doesn't take effect when running tests (e.g. via Test Explorer). I also know I can pass test parameters through a .runsettings
files, but these are accessible only through the TestContext
class.
You can also specify environment variables in the
.runsettings
file:Alternatively (if you need to run code or calculate the value) you can implement a
DataCollector
which provides environment variables viaITestExecutionEnvironmentSpecifier
You also configure your data collector via the
.runsettings
file: