简体   繁体   中英

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?

I want to use the category to filter out the tests.

Currently, your test method will only be category 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

In a technical sense, P1 is the category of TestClass and P2 is the category of 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:

--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:

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

IOW, it acts like the category is inherited, although it isn't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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