【发布时间】:2018-01-23 19:01:32
【问题描述】:
我正在 Visual Studio (2017) 中为基于 VSTS 并从那里部署的 Net Core 应用程序构建集成测试。我的项目是测试项目,现在我到已部署 API url 的连接字符串和数据库是硬编码的,但我想从代码中删除它们并将它们放在添加环境变量的 VSTS 构建步骤中。
现在,我的 Test .cs 文件如下所示:
[TestClass]
public class TestFeature
{
//Set up variables
private static string _connectionString = "server=localhost;port=5432;database=databaseName;user id=postgres;password=postgres";
[TestInitialize]
public void Initialize()
{
}
//And going into my test methods
}
如何设置我的项目以读取 VSTS 上的配置中设置的环境变量?
到目前为止,我发现的研究是在 Debug 下的测试项目的 Properties 上右键单击,设置带有键和值的环境变量。
然后我更改我的测试项目以获取 GetEnvironmentVariable()
private static string _connectionString = Environment.GetEnvironmentVariable(nameOfVariable);
在 VSTS 的另一边,我试图找到一个构建步骤,将变量设置为那里的连接字符串。我能找到的最佳步骤是“设置变量”。
但是,这对我不起作用。程序将无法识别环境变量中设置的新变量的名称,无法启动。
【问题讨论】:
标签: .net-core environment-variables azure-devops integration-testing azure-pipelines