从 SpecFlow 设置 Nunit TimeoutAttribute

发布于 2025-01-08 14:14:07 字数 155 浏览 1 评论 0原文

我使用 SpecFlow 编写了几个长时间运行的端到端集成测试,但由于 Nunit 超时而失败。

将 [Timeout(x)] 属性添加到 TestFixture 可以解决问题,但当然每次功能更新时都会被覆盖。

如何以 SpecFlow 尊重的方式删除或延长超时?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

溺孤伤于心 2025-01-15 14:14:07

我刚刚开始了解 Specflow,但是您可以实现一个可以执行此操作的自定义标签吗?也许您可以将它们放在 BeforeScenario 或 BeforeFeature 挂钩中?

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?

何以畏孤独 2025-01-15 14:14:07

我们谈论的跑步时间有多长? > 1分钟?
是否必须是完整的集成测试?

我正在读黄瓜书 - 它建议您尽可能多地作弊给定的步骤,以减少运行所需的时间。给出的步骤描述的是过去。

我的申请表有 5 个部分需要填写,只有在所有部分都完成后才能提交。我想测试提交应用程序时发生的一些功能,最初我的 GIVEN 语句通过 Selenium 驱动网页来完成表单的所有 5 个部分,以便我可以提交,我将其更改为单个 SQL 命令来设置应用程序所有待完成部分的状态。这减少了大约一分钟的运行时间。

我正在测试的是提交行为,填写部分测试是在其他地方完成的。

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.

深府石板幽径 2025-01-15 14:14:07

正如@DisscCoder 所说,
在功能文件中的场景中添加标签类别,并在钩子类中添加匹配的钩子....
SpecFlow 对字符串匹配的所有场景运行之前的场景代码挂钩代码。

namespace ClassLibrary1
{
    [Binding]
    public class Hooks1
    {               
        [BeforeScenario("LongTest")]
        public void BeforeScenario()
        {
             // Code to set Nunit timeout
        }                         
    }
}

小黄瓜:

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

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...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文