【问题标题】:Multiple categories for nunit through testfixture and test attributes通过 testfixture 和 test 属性为 nunit 提供多个类别
【发布时间】:2017-10-31 17:25:25
【问题描述】:
[TestFixture(Category = "P1")]
public class TestClass 
{
    [Test(Category = "P2")]
    public void Method()
    {
        //test
    }
}

在上面的代码 sn-p 中,TestCategoryMethod 将被视为:“P1”或“P2”或两者兼而有之?

我想使用类别来过滤掉测试。

【问题讨论】:

标签: unit-testing testing nunit


【解决方案1】:

从技术上讲,P1 是TestClass 的类别,P2 是Method 的类别。这很清楚。

正如 Chris 所指出的,类别不是继承的。但是,对于大多数过滤目的而言,这对您来说并不重要。

控制台运行器命令行上的以下任一选项将运行方法:

--where "cat==P1" --where "cat==P2"

以下任何一项都将排除方法

--where "cat!=P1" --where "cat!=P2"

这个命令会运行TestClass中的所有测试除了 for Method:

--where "cat==P1&&cat!=P2"

IOW,它表现得像类别是继承的,虽然它不是。

【讨论】:

  • -- "cat==P1&&cat==P2" 将在哪里运行“方法”?
  • @IshuGoyal 不,不会。这是类别显示其真实颜色的情况。由于类上的属性是继承的,所以它只有类别P2。我应该说(已编辑)“出于大多数目的”
【解决方案2】:

目前,您的测试方法将仅为 P2 类。

类别目前没有被继承。这里有开放的 GitHub 问题可以改变这种行为:https://github.com/nunit/nunit/issues/796 和这里:https://github.com/nunit/nunit/issues/1396

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-01
    • 1970-01-01
    相关资源
    最近更新 更多