具有不同类别属性的NUnit Multiple TestFixture [英] NUnit Multiple TestFixture with different Category attribute
问题描述
我有一个带有多个TestFixture的测试类,并且我想为每个testfixture提供不同的类别,例如:
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
}
当我使用nunit3-console运行程序进行测试时给出--"cat == A"时,它仍然为两个网站都运行测试方法.有没有一种方法可以对这种模型中的一个类别进行测试?
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?
推荐答案
语法上有一个小错误.使用单独的CategoryAttribute
进行指定的方法是将这两个类别整体应用于该类.而是要在TestFixtureAttribute
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")]
您当前拥有的等同于:
[TestFixture("WebsiteA")]
[TestFixture("WebsiteB")]
[Category("A")]
[Category("B")]
public class LoginTests
{
这篇关于具有不同类别属性的NUnit Multiple TestFixture的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!