NUnit Multiple TestFixture with different Category attribute

百般思念 提交于 2019-12-11 00:49:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!