11

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.

1 Answer 1

26

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Totally forgot about that. I use it to read the variables. Thanks!
Not working in Azure DevOps pipelines with ubuntu hosted agent. Any other ideas ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.