【问题标题】:How to use exclude a category attribute in Nunit command line Execution如何在 Nunit 命令行执行中使用排除类别属性
【发布时间】:2020-08-30 14:56:39
【问题描述】:

我只想在命令行执行期间从下面排除 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);
     }

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

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

【问题讨论】:

    标签: c# unit-testing jenkins nunit nunit-console


    【解决方案1】:

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

    您目前拥有的,在 C# 术语中等同于以下内容:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2017-10-31
      • 1970-01-01
      • 2015-01-26
      • 2012-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-13
      • 2012-06-20
      相关资源
      最近更新 更多