1
[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.

Bleh
  • 441
  • 3
  • 14

2 Answers2

2

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.

Charlie
  • 12,928
  • 1
  • 27
  • 31
  • --where "cat==P1&&cat==P2" will this run 'Method'? – Bleh Oct 31 '17 at 21:15
  • @IshuGoyal No, it won't. This is the case where the category shows it's true colors. Since the attribute on the class is _not_ inherited, it only has category P2. I should have said (EDITED) "for __most__ purposes" – Charlie Nov 11 '17 at 17:47
1

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

Chris
  • 5,882
  • 2
  • 32
  • 57