问题
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?
回答1:
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
{
来源:https://stackoverflow.com/questions/38901728/nunit-multiple-testfixture-with-different-category-attribute