Megha
Megha

Reputation: 529

NUnit Multiple TestFixture with different Category attribute

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?

Upvotes: 2

Views: 3062

Answers (1)

Chris
Chris

Reputation: 6042

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 
{

Upvotes: 3

Related Questions