Set Nunit TimeoutAttribute from SpecFlow

谁说我不能喝 提交于 2019-12-05 01:30:18

问题


I've written several long running end to end integration tests using SpecFlow, but they are failing due to Nunit timeouts.

Adding the [Timeout(x)] attribute to the TestFixture solves the issue, but of course gets overwritten everytime the feature is updated.

How can I remove or extend the timeout in a way that SpecFlow will respect?


回答1:


I am only getting to understand Specflow but could you implement a custom tag that could do this? Maybe you could place these at the BeforeScenario or BeforeFeature hooks?




回答2:


How long running are we talking about? > 1 minute? Does it have to be a full integration test?

I was reading the cucumber book - it suggested that you cheat as much as possible for your GIVEN steps to reduce the time it takes for things to run. GIVEN steps are describing the past.

I have an application form that has 5 sections to complete and can only be submitted once all sections are completed. I wanted to test some functionality that occurs on submission of the application, originally my GIVEN statements were driving the webpage through Selenium to complete all 5 sections of the form so that I could submit, I changed this to a single SQL command to set the app status for all the sections to completed. This chopped about a minute off the runtime.

The thing I was testing was the submission behaviour, the filling out the sections tests are done elsewhere.




回答3:


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...


来源:https://stackoverflow.com/questions/9412669/set-nunit-timeoutattribute-from-specflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!