gpt4 book ai didi

nunit - 如何教 SpecFlow 向我的测试类添加额外的 NUnit 属性

转载 作者:行者123 更新时间:2023-12-04 10:55:07 29 4
gpt4 key购买 nike

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)并注册到 unitTestProvidergeneratorProvider配置的 specflow 部分中的属性。

您可以在 github 找到内置实现的源代码。 .

关于nunit - 如何教 SpecFlow 向我的测试类添加额外的 NUnit 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11009181/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com