We can execute a test server for integration testing. Something like:
Fine.
However, I can't pass environment variables to the test server.
I can set the environment with UseEnvironment("Development")
but not add variables.
It should be possible, but I don't know how to do it.
Anyone Knows how this can be done?
The environment variables would carry dev logins for a 3rd party API our code base needs. For unit tests we mock this 3rd party API. A solution for my specific problem can be to mock this for integration tests as well, thus removing the need for environment variables, but even so the question remains.
Open project properties by right clicking on the project in the solution explorer and select Properties. This will open properties page. Click on Debug tab and you will see Environment Variables as shown below. You may change the value as per your need.
Environment Variables are one of the sources from which ASP.NET Core reads the configuration values. In this tutorial, let us learn how to set Environment Variables in Windows, Mac, Linux, IIS Server, Visual Studio, Visual Studio Code & dotnet run. We also learn how to read them in ASP.NET core.
Integration tests ensure that an app's components function correctly at a level that includes the app's supporting infrastructure, such as the database, file system, and network. ASP.NET Core supports integration tests using a unit test framework with a test web host and an in-memory test server.
You can set an environmental variable programmatically.
System.Environment.SetEnvironmentVariable("key", "value");
MSDN writes that SetEnvironmentVariable(string, string)
...
Creates, modifies, or deletes an environment variable stored in the current process... Because the environment variable is defined in the environment block of the current process only, it does not persist after the process has ended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With