SpecFlow 很棒 - 它非常有助于我们进行适当的集成测试。
我想知道的一件事是,是否有办法告诉 SpecFlow 将其他 NUnit 属性添加到它在功能代码隐藏文件中创建的测试类中。
现在,我的测试类生成如下内容:
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.8.1.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[NUnit.Framework.TestFixtureAttribute()]
[NUnit.Framework.DescriptionAttribute("Some action description here")]
public partial class MySampleFeature
{
......
}
SpecFlow 中有什么方法可以告诉它添加一个额外的 NUnit 属性来定义测试的类别 - 如下所示:
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.8.1.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[NUnit.Framework.TestFixtureAttribute()]
[NUnit.Framework.DescriptionAttribute("Some action description here")]
[NUnit.Framework.Category("LongRunningTests")] <== add this "Category" attribute
public partial class MySampleFeature
{
......
}
手动将其添加到生成的代码隐藏中是浪费的 - 下次 SpecFlow 重新生成该代码隐藏时,我必须记住再次这样做(很有可能,我会忘记)。
如果该功能在 SpecFlow 中尚不存在 - 如何请求添加此功能? :-)
事实上,如果在功能或方案中使用标记(查找标记部分),则已支持 NUnit.Framework.Category
属性。所以如果你写
@LongRunningTests
Feature: MySampleFeature
它将生成正确的Category
属性。
但是,如果要具有其他自定义属性,则需要编写一个具有实现IUnitTestGeneratorProvider
接口的自定义生成器提供程序,并在配置的specflow部分中注册unitTestProvider的generatorProvider
属性。
你可以在github上找到内置实现的来源。
添加后,要添加到@nemesv的好答案中:
@LongRunningTests功能:我的样本功能
要从控制台执行,请执行以下操作:
nunit3-console.exe myTests.dll --where "cat==LongRunningTests"