Dar*_*g8r 5 nunit azure-devops azure-pipelines
我有一个 api 项目,我想在 Azure 发布管道中运行一些集成测试。
我被困在第 4 步。很容易将参数传递给 Visual Studio 中的测试装置。
[TestFixture(arguments: "https://urltomyslot.azurewebsites.net")]
public class CachedClientApiTokenManagerTests
{
public CachedClientApiTokenManagerTests(string authority)
{
_authority = authority;
}
private readonly string _authority;
// Runs tests using the url
}
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么做是根据环境从 Azure Devops 传递参数。我正在使用 NUnit3TestAdapter 包并且它运行良好,但 args 是症结所在。如果我们在实验室环境中执行此操作,则传递的 url 与暂存或生产 url 不同。
我们如何使用 args 在 Azure DevOps 中配置它?
您可以在变量中定义环境:
然后用这种方式读取 C# 代码中的变量:
string environment = Environment.GetEnvironmentVariable("environment", EnvironmentVariableTarget.Process);
Run Code Online (Sandbox Code Playgroud)
现在取决于environment创建 URL的值并运行测试。
例如,我创建了一个小的控制台应用程序:
class Program
{
static void Main(string[] args)
{
string environment = Environment.GetEnvironmentVariable("environment", EnvironmentVariableTarget.Process);
if (environment == "prod")
{
Console.WriteLine("We are in production :)");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我配置了变量:
我运行.exe文件,在输出中我可以看到We are in production :)打印的:
| 归档时间: |
|
| 查看次数: |
2711 次 |
| 最近记录: |