NUnit.Framework: 如何运行 带有AND 和OR 选项的类别?

NUnit.Framework: How to run categories with AND and OR option?

NUnit.Framework: 如何运行 带 AND 和 OR 选项的类别?

我在测试方法中定义了我的类别,例如:

第一种方法:

[<Test>]
   [<Category("Smoke")>]
   [<Category("Reg")>]

第二种方法:

[<Test>]
   [<Category("Sanity")>]
   [<Category("Reg")>]

第三种方法:

[<Test>]
   [<Category("Sanity")>]
   [<Category("Smoke")>]

第四种方法:

[<Test>]
   [<Category("Reg")>]
   [<Category("Login")>]

我可以使用以下方法过滤并 运行 特定测试:dotnet test --filter TestCategory=Smoke

现在我的要求是运行: 1) 所有具有 Sanity AND Smoke 类别的方法(在上述情况下应该 运行 只有第三种方法)。我试过:dotnet test --filter "TestCategory=Sanity" && "TestCategory=Smoke" 但它不起作用。

2) 所有具有 Sanity 或 Smoke 类别的方法(在上述情况下应该 运行 除了第 4 个之外)。我试过了:dotnet test --filter "TestCategory=Sanity" || "TestCategory=Smoke" 但它不起作用。

当涉及到 运行 NUnit 类别时,请建议我如何 运行 AND 和 OR?

dotnet test --filter <expression> 选项采用单个参数,即过滤器表达式。您提供了三个参数。

此外,由于您使用的是dotnet test命令,因此您必须使用微软认可的运算符和特征。来自 NUnit 的测试选择语言的运算符将无法工作,除非它们也被 Microsoft 使用。

在这种情况下,您正在寻找 dotnet test --filter "TestCategory=Sanity|TestCategory=Smoke"

请注意,根据您正在使用的命令shell,您需要对上述表达式中的字符进行转义。在 Windows 上,我相信双引号会起作用。在 Linux 上,根据您的 shell,您可能需要使用单引号。

这里很好地介绍了过滤器表达式的语法:https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test