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如果您使用 tags (look for the tags section),则已支持属性关于您的功能或场景。所以如果你写
@LongRunningTests
Feature: MySampleFeature
它将生成正确的
Category属性。
但是,如果您想拥有额外的自定义属性,您需要编写自定义生成器提供程序并实现
IUnitTestGeneratorProvider。接口(interface)并注册到
unitTestProvider的
generatorProvider配置的 specflow 部分中的属性。
您可以在 github 找到内置实现的源代码。 .




