从SpecFlow设置NUnit的TimeoutAttribute [英] Set Nunit TimeoutAttribute from SpecFlow
问题描述
我已经写了几个长期运行结束使用SpecFlow结束集成测试,但他们未能由于NUnit的超时。
I've written several long running end to end integration tests using SpecFlow, but they are failing due to Nunit timeouts.
添加[超时(X)]属性到的TestFixture解决了这个问题,当然,被覆盖每次的功能更新。
Adding the [Timeout(x)] attribute to the TestFixture solves the issue, but of course gets overwritten everytime the feature is updated.
如何删除或延长超时的方式,SpecFlow会尊重?
How can I remove or extend the timeout in a way that SpecFlow will respect?
推荐答案
作为@ Dissc codeR说, 添加标签分类到方案中的功能文件中,并添加一个挂钩相匹配,那么挂钩类.... SpecFlow运行前情景code勾code为所有场景的字符串匹配。
As @DisscCoder says, Add a tag category to the scenario in the feature file, and add a hook that matches in a hooks class.... SpecFlow runs the before scenario code hook code for all scenarios where the string matches.
namespace ClassLibrary1
{
[Binding]
public class Hooks1
{
[BeforeScenario("LongTest")]
public void BeforeScenario()
{
// Code to set Nunit timeout
}
}
}
小黄瓜:
Gherkin:
@LongTest
Scenario: Calc Pi to 1m digits (long)
Given I am computing PI
And my precision is 1 million digits
Then my result is 3.14...
这篇关于从SpecFlow设置NUnit的TimeoutAttribute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!