2

I have a test class with multiple TestFixture and I want to provide different category per testfixture like:

[TestFixture("WebsiteA"), Category("A")]
[TestFixture("WebsiteB"), Category("B")]
public class LoginTests 
{
    public LoginTests(string websiteName) 
    {
    }
    [Test]
    //test
}

When I am running test with nunit3-console runner giving stating --where "cat==A" then it still run the test method for both websites. Is there a way to run test for just one category in this kind of model?

Megha
  • 509
  • 5
  • 16

1 Answers1

3

You have a minor error in your syntax. How you are specifying it, is using the separate CategoryAttribute, which is applying both categories to the class as a whole. Instead, you want to be setting the Category property on the TestFixtureAttribute

[TestFixture("WebsiteA", Category="A")]
[TestFixture("WebsiteB", Category="B")]

What you currently have is the equivalent of:

[TestFixture("WebsiteA")]
[TestFixture("WebsiteB")]
[Category("A")]
[Category("B")]
public class LoginTests 
{
Chris
  • 5,882
  • 2
  • 32
  • 57
  • @Chris, one issue... do you know of any syntax if we want to add two different Categories to the same TestFixture? I've tried Category="A,C", but the problem is that when I run my Nunit tests, the category appears as "A,C", rather than as two different categories, A and C... – mickael Jul 18 '18 at 10:38
  • Comma separated should work - see https://github.com/nunit/nunit/blob/b6ad1a9c22baaa1562511d09ae559b67344ae4e6/src/NUnitFramework/framework/Attributes/TestFixtureAttribute.cs#L209 Maybe double check this in the latest version of the framework, and then file a bug? A pull request to fix this would be very welcome - so long as the team can agree it's a bug, and not intentional! – Chris Jul 18 '18 at 13:31
  • It seems to work in team city but not when Visual Studio/Resharper create the unit test sessions. In team city, it creates two different categories, one for "A" and one for "C", in VS/Resharper the session appears as a single category, such as "A,C". It seems it might not be an Nunit bug but something to do with the VS or Resharper? I couldn't find an option to modify this behaviour though... – mickael Jul 20 '18 at 09:41
  • @mickael did you ever work this out? Having the same issue now – IeuanW May 04 '20 at 09:49