如何使用--where来运行TestCases的子集

问题描述 投票:0回答:1

对于我的项目,我想在完全相同的测试用例中运行两次,一次是在本地运行,另一个是在云中并行运行在不同的VM上(在我的案例中是Azure)。

我复制了TestCase,并标记了一个Category("Local")和另一个Category("Cloud")。因此,使用--where="cat == Cloud"从控制台运行nunit3将运行每个测试的所有TestCases,每个测试都有一个或多个标有Category("Cloud")的测试案例。

是否有其他方法仅通过命令行开关运行选定的TestCases?

简化示例:

[TestCase(TestName = "Canary, Run in cloud."), Category("Cloud")]
[TestCase(TestName = "Canary, Run locally."), Category("Local")]
public void Canary()
{
    Assert.True(true);
}
nunit testcase nunit-console
1个回答
0
投票

找到了解决方法。使用--params:Cloud=true作为命令行参数并在代码中>>

private bool ShallRunInCloud => TestContext.Parameters["Cloud"]?.ToLowerInvariant() == "true";
© www.soinside.com 2019 - 2024. All rights reserved.