简体   繁体   English

有没有办法使用 NUnit 跳过 Specflow 中的一个步骤?

[英]Is there a way to skip a step in Specflow with NUnit?

I have a test case where I included a step that applies to all markets I run this against but one.我有一个测试用例,其中包含一个适用于我所针对的所有市场的步骤,但只有一个。 I would like to skip this step in this scenario.我想在这种情况下跳过这一步。

This is what I am currently doing, but I am wondering if there is a built in function.这是我目前正在做的,但我想知道是否有内置的 function。 I have searched and I am not having much luck, thanks.我已经搜索过,但运气不佳,谢谢。

[Then(@"Verify Yearly AutoOrder was created from enrollment")]
public void ThenVerifyYearlyAutoOrderWasCreatedFromEnrollment()
{
    if (!Market.Equals("in"))
    {
        this.srEnrollPage.VerifyYearlyAutoOrderWasCreatedFromEnrollment(this.dataCarriers.orderNumber, this.dataCarriers.userEmail);
    }
    else
    {
        return; // India does not have yearly autoOrders as of now.
    }
}

There are two things that make me nervous about "skipping" a step.有两件事让我对“跳过”一步感到紧张。

From a behavior-driven development perspective, India deserves its own scenario explicitly stating that auto orders are not created:从行为驱动的发展角度来看,印度应该有自己的场景,明确指出没有创建汽车订单:

Scenario: Auto orders are not created in India after enrollment
    Given the market is "India"
    And ...
    When something about enrolling
    Then a yearly auto order should not be created from the enrollment

This new step would assert something to the effect of:这一新步骤将断言以下内容:

this.srEnrollPage.VerifyYearlyAutoOrderWasNotCreatedFromEnrollment(...);
//                                        ^^^

This is all fine if practicing real behavior-driven development.如果实践真正的行为驱动开发,这一切都很好。 I understand that many people use Gherkin/SpecFlow as an automation framework for QA testing.我知道很多人使用 Gherkin/SpecFlow 作为 QA 测试的自动化框架。 In that case, consider making the opposite assertion for India:在这种情况下,考虑对印度做出相反的断言:

[Then(@"Verify Yearly AutoOrder was created from enrollment")]
public void ThenVerifyYearlyAutoOrderWasCreatedFromEnrollment()
{
    if (Market == "in")
    {//        ^^
        this.srEnrollPage.VerifyYearlyAutoOrderWasNotCreatedFromEnrollment(...);
        //                                     ^^^^^^
    }
    else
    {
        this.srEnrollPage.VerifyYearlyAutoOrderWasCreatedFromEnrollment(...);
        //                                     ^^^
    }
}

Simply passing the scenario or skipping the step could hide problems with the application if it suddenly starts creating auto orders for India.如果应用程序突然开始为印度创建自动订单,简单地通过场景或跳过该步骤可能会隐藏应用程序的问题。 I would want a failing test if some developer ignored this business rule and created the orders anyhow.如果某些开发人员忽略了这个业务规则并无论如何创建了订单,我会想要一个失败的测试。 With your suggestion, the test would pass even if an auto order gets mistakenly created for India.根据您的建议,即使错误地为印度创建了自动订单,测试也会通过。

The assertion should always assert something.断言应该总是断言一些东西。 If you cannot assert the auto order was created, at least assert the auto order wasn't created, so you can catch application failures instead of accidentally hiding them.如果您无法断言自动订单已创建,至少要断言自动订单创建,这样您就可以捕获应用程序故障而不是意外隐藏它们。

Don't assume India does not get auto orders.不要假设印度没有汽车订单。 Prove it by making the appropriate assertion.通过做出适当的断言来证明它。

You can use simply Assert.Pass();您可以简单地使用Assert.Pass(); but consider rewriting the tests to cover the scenarios (as @greg-burghardt said).但考虑重写测试以涵盖场景(如@greg-burghardt 所说)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM