如何教SpecFlow向我的测试类添加其他NUnit属性

如何教SpecFlow向我的测试类添加其他NUnit属性,nunit,specflow,class-attributes,Nunit,Specflow,Class Attributes,非常好——这对我们进行适当的集成测试非常有帮助 我想知道的一件事是,是否有办法告诉SpecFlow向它在featurecodebhind文件中创建的测试类添加额外的NUnit属性 现在,我的测试类生成如下内容: [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.8.1.0")] [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]

非常好——这对我们进行适当的集成测试非常有帮助

我想知道的一件事是,是否有办法告诉SpecFlow向它在featurecodebhind文件中创建的测试类添加额外的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
{  
   ......
}
[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中是否有任何方法告诉它添加一个额外的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
{  
   ......
}
[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
{  
   ......
}
[System.CodeDom.Compiler.GeneratedCodeAttribute(“TechTalk.SpecFlow”,“1.8.1.0”)]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[NUnit.Framework.TestFixtureAttribute()]
[NUnit.Framework.DescriptionAttribute(“此处的一些操作描述”)]

[NUnit.Framework.Category(“LongRunningTests”)]事实上,如果您在功能或场景中使用,
NUnit.Framework.Category
属性已经得到支持。所以如果你写

@LongRunningTests
Feature: MySampleFeature
它将生成适当的
类别
属性

但是,如果希望具有其他自定义属性,则需要编写一个自定义生成器提供程序,实现
IUnitTestGeneratorProvider
接口,并在配置的specflow部分中的
generatorProvider
属性中注册


您可以在。

找到内置实现的来源,添加到@nemesv的好答案中,一旦添加:

@长期运行试验 功能:MySampleFeature

要从控制台执行,请执行以下操作:


nunit3-console.exe myTests.dll——其中“cat==LongRunningTests”

这在SpecFlow 1.9中似乎不可能,因为无法访问IUnitTestGeneratorProvider接口。该文档声明,当v.2.0发布时,将用插件替换提供程序。例如,我想实现一个自定义的xUnitGeneratorProvider,以便将标记推出到xUnit.NET Traits。你需要创建一个新的项目来承载你的SpecFlow插件。在这个项目中,安装SpecFlow numget包和SpecFlow.Plugins numget包。Plugins NuGet包包含允许您创建SpecFlow插件的程序集;其中一个程序集中是
IUnitTestGeneratorProvider
IUnitTestGeneratorPlugin
接口(我相信每个接口都有一个基类实现)。