我们可以执行一个测试服务器来进行集成测试。像这样的东西:
很好。
但是,我无法将环境变量传递给测试服务器。
我可以使用 UseEnvironment("Development")
设置环境,但不能添加变量。
应该可以,但我不知道怎么做。
有人知道如何做到这一点吗?
环境变量将为我们的代码库所需的第 3 方 API 提供开发登录。 对于单元测试,我们模拟这个第 3 方 API。 我的特定问题的解决方案也可以是为集成测试模拟它,从而消除对环境变量的需要,但即便如此问题仍然存在。
最佳答案
您可以通过编程方式设置环境变量。
System.Environment.SetEnvironmentVariable("key", "value");
MSDN写道 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.
关于c# - 内存中集成测试和环境变量——.net core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42030238/