【问题标题】:possible to use specflow to write non-bdd procedural tests?可以使用 specflow 编写非 bdd 程序测试吗?
【发布时间】:2011-11-15 00:40:26
【问题描述】:

specflow 看起来像是我希望我的团队考虑使用的解决方案。然而,我的经理并不真正喜欢 BDD 风格的测试。由于 specflow 与 Visual Studio 的完美集成,我想知道是否可以利用 specflow 框架,同时允许较少 bdd 样式的测试形式。

例如,不要编写如下测试:

Scenario: Help->About
  Given a user is logged in to "http://..." as "user/password"
    And they are on the page titled "Home"
   When I click on "about"
   Then I should see a window titled "about"

...我想写成:

Scenario: Help->About
  log in to "http://..." as "user/password"
  click on the "About" link
  assert "About" window should be visible

换句话说,必须我使用 GivenThen 等关键字,还是 specflow 能够处理不以这些词开头的步骤?

【问题讨论】:

    标签: specflow


    【解决方案1】:

    Specflow 在代码生成器中使用 Given、When 和 Then 关键字来生成如下测试用例:

        [NUnit.Framework.TestAttribute()]
        [NUnit.Framework.DescriptionAttribute("See the content of a message")]
        public virtual void SeeTheContentOfAMessage()
        {
            TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Help->About", ((string[])(null)));
            this.ScenarioSetup(scenarioInfo);
            testRunner.Given("a user is logged in to \"http://\" as user/password");
            testRunner.When("I click on About"); 
            testRunner.Then("I should see a window titled about");
            testRunner.CollectScenarioErrors();
        }
    

    将测试更改为您描述的方式的唯一方法是更改​​代码生成器。 GherkinDialect 中的 TryParseStepKeyword() 方法是一个好的开始

    【讨论】:

      【解决方案2】:

      我认为很大程度上是你如何解释给定、何时和然后。我们发现最好的方法是 Given 应该为测试准备状态。何时应该是您要测试的操作,然后应该是验证。当您从这种方法中考虑时,这两个示例都非常相似。就个人而言,我喜欢第二种更通用的风格。这样,您就不会将您的功能绑定到一组特定的步骤,而是测试行为。说这样的测试真的不需要更多。例如。

      Scenario: Help->About
      Given a user is logged in
      When you navigate to the the About page
      Then the about information should be displayed
      

      我尽量不使用点击等特定操作。最后由您决定如何描述这些步骤,但 specflow 确实使用 Given/When/Then 进行代码生成。不过,您不需要全部使用。

      【讨论】:

        猜你喜欢
        • 2011-05-08
        • 1970-01-01
        • 2011-07-26
        • 2012-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多