简体   繁体   English

通过测试治具和测试属性的nunit的多个类别

[英]Multiple categories for nunit through testfixture and test attributes

[TestFixture(Category = "P1")]
public class TestClass 
{
    [Test(Category = "P2")]
    public void Method()
    {
        //test
    }
}

In the above code snippet, what will be considered the TestCategory of Method : "P1" or "P2" or both? 在上面的代码片段中,什么将被视为MethodTestCategory :“ P1”或“ P2”或两者兼而有之?

I want to use the category to filter out the tests. 我想使用类别来过滤掉测试。

Currently, your test method will only be category P2. 当前,您的测试方法将仅是类别P2。

Categories are currently not inherited. 当前未继承类别。 There are open GitHub issues to change that behaviour here: https://github.com/nunit/nunit/issues/796 and here: https://github.com/nunit/nunit/issues/1396 此处存在开放的GitHub问题来更改此行为: https : //github.com/nunit/nunit/issues/796和此处: https : //github.com/nunit/nunit/issues/1396

In a technical sense, P1 is the category of TestClass and P2 is the category of Method. 从技术上讲,P1是TestClass的类别,P2是Method的类别。 That's clear. 很清楚

As Chris points out, categories are not inherited. 克里斯指出,类别不是继承的。 However, that's not important to you for most purposes of filtering. 但是,对于大多数过滤目的而言,这对您而言并不重要。

Either of the following options on the console runner command line will run Method: 控制台运行程序命令行上的以下任何一个选项都将运行Method:

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

Either of the following will exclude Method 以下任一情况都将排除方法

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

This command would run all the tests in TestClass except for Method: 此命令将运行TestClass中的所有测试(方法除外)

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

IOW, it acts like the category is inherited, although it isn't. IOW,它的作用就像继承了类别,尽管不是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM