How to set Environment to "Test" for unit test runner?

Answered

Hello,

We have a slightly different configuration for our "Test" and "Development" environments than we do for "Production", but I cannot figure out a way to set the Environment to "Test" when running within the Rider Unit Test runner. On the command line, I can do "ASPNETCORE_ENVIRONMENT=Test dotnet test" which works great. How can I achieve something similar within Rider?

Thanks!

6
6 comments
Avatar
Permanently deleted user

have you found the solution for this yet? I'm looking for the same thing

1
Avatar
Permanently deleted user

David, unfortunately we have not figured out a solution to this :(

0
Avatar
Permanently deleted user

In the end, I work around this by programatically set environment to Test in a base class for all unit tests:

Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Test");

It's not ideal but it works for me. I was looking for setting this variable in unit test project appsettings.json file but seem like it doesn't support.

0

Looks like there isn't a proper way to do this within Rider currently. You might want to vote this request up.

1
Avatar
Permanently deleted user

In 2018+, can add environment variables in "Unit Testing Settings" (Preferences > Build, Execution, Deployment > Unit Testing > Test Runner). Still bad this can't be saved as different 'test runner configurations' (similar to 'run/debug configurations').

3
Avatar
Permanently deleted user

What Omar said. But be careful, when you add keys like this they are stored in lowercase.

 

 

0

Please sign in to leave a comment.