如何在 Nunit 命令行执行中使用排除类别属性

How to use exclude a category attribute in Nunit command line Execution

我只想在命令行执行期间从下面排除 1 个测试用例参数

nunit3-console.exe Excel.Test.dll --where="cat!=IgnoreForNow"

但这排除了所有参数(A、B、C、D)

 [TestCase("A"), Category("IgnoreForNow")]
 [TestCase("B")]
 [TestCase("C")]
 [TestCase("D")]
 public void TestReports(string fileName)
     {
         Test("foo", fileName);
     }

我不想使用 ignore 属性,因为我想在构建系统中跳过此测试用例执行,但想在本地执行它们。

从命令行执行时在 NUnit 中有什么方法

您的方法和命令行是正确的,但是您当前使用类别属性的方式不正确。

您当前拥有的内容等同于以下 C# 术语:

 [TestCase("A")]
 [TestCase("B")]
 [TestCase("C")]
 [TestCase("D")]
 [Category("IgnoreForNow")]
 public void TestReports(string fileName)
     {
         Test("foo", fileName);
     }

通过这样做,您将该类别应用于整个 TestReports 测试套件 - 这就是排除所有个别案例的原因。

您需要做的是在 TestCaseAttribute 上使用 Category 属性,如下所示:

 [TestCase("A", Category="IgnoreForNow")]
 [TestCase("B")]
 [TestCase("C")]
 [TestCase("D")]
 public void TestReports(string fileName)
     {
         Test("foo", fileName);
     }