In my integration tests, I want to set a specific connection string when the test runs in a development environment, and another connection string when the test runs in the staging environment.
When I am not in testing mode, I simply set the environment variable on the machine, and all work OK. But on testing I can use UseEnvironment(envX)
, but then it'll be envX
on all machines, or not use this method, and get the default one (which is production).
So, how can I use multiple connection strings, environment based, in my integration tests?
Instead of using
UseEnvironment(envX)
you could set the environment variableASPNETCORE_ENVIRONMENT
before running the tests.I.e.
SET ASPNETCORE_ENVIRONMENT=Test
andSET ASPNETCORE_ENVIRONMENT=SomeOtherEnvironment