【问题标题】:confusion implementing specflow bdd for resource-based api为基于资源的 api 实现 specflow bdd 的困惑
【发布时间】:2014-10-21 23:29:56
【问题描述】:

我第一次尝试将 bdd 实施到一个项目中,并且对针对受众使用的语言有几个问题。

我已经看到了很多示例,其中该语言旨在被最终用户等理解。但是,如果您正在编写一个即将被使用的 api(带有 odata 支持的 rest 样式 web-api)呢?由其他开发商?可以更具体一些,还是应该尽量保持简单?

其次,如果你在一般意义上描述它,你是否必须在中指定值,例如:

Scenario: product is defined for the first time

Given product code abcdefg does not already exist

When product definition with code abcdefg is uploaded

Then product is created

And user receives status 201 created with url 'blah'

但是可以将其抽象为更一般的情况吗?例如

Scenario: product is defined for the first time

Given product code does not already exist

When product definition is uploaded

then product is created

And user receives status 201 and creation url

谢谢

更新

感谢 sam 和 AlSki,我们决定将规范分为 3 种不同类型:

User: End-User facing, most declarative style concerning UI

Dev: More imperative and detailed, concerning data only interactions

System: Most imperative and detailed - concerning our internal stuff

现在正在创建包含多个示例的场景大纲,这似乎可以很好地测试我们所有的边缘案例。

我还删除了外部开发人员无法观察到的结果(“产品已创建”等),并认为我们现在都更好地理解了这一点。

【问题讨论】:

    标签: bdd specflow gherkin


    【解决方案1】:

    第一个问题的答案是肯定的。你可以在 BDD 中做任何你想做的事,只要它对将要使用它的人有意义。

    所以,如果您是一个完全技术团队并且都乐于使用状态码 201url,那么请继续。

    阅读 BDD 倡导者(Dan NorthLiz KeoghGojko Adzic 等),您会发现重要的一点是与其他人交谈并在您的规范中使用相同的语言你在谈话中使用的,因为你正在封装你的知识并用它来测试。

    但是,您的第二个示例可能有点过头了。考虑 BDD 也称为 Specification by example,在这种情况下,您已删除该示例。您只有一个大致的想法,但也没有具体的测试。

    考虑是否出于某种原因(我们都见过其中之一),是否有一个特殊的产品代码可以做一些不同的事情。你会如何测试呢?

    【讨论】:

    • 感谢您的澄清。我看过 Dan Norths 的东西,但每当我试图充实细节时,我最终都会为边缘情况编写大量场景,所以我认为更通用的方法可能会有所帮助。
    • +1 查看具体示例。我通常会问,“你能给我举个例子吗?”无论专家是谁,然后尝试在场景中尽可能多地使用该语言。也谢谢你的插件! - 丽兹。
    【解决方案2】:

    您可以做的是提取通用但在测试中保持特异性的步骤:

    Scenario: product is defined for the first time
       Given product code 'abcdefg' does not already exist
       When product definition with code 'abcdefg' is uploaded
       Then product 'abcdefg' is created
       And user receives status 201 created with url 'blah'
    

    绑定到如下步骤:

    [Given("product code '(.*)' does not already exist")]
    public void ProductCodeDoesNotExist(string productCode)
    {...}
    

    然后您可以重复使用相同的步骤来测试许多产品

    另外我建议你换个步骤:

     And user receives status 201 created with url 'blah'
    

    到一些不太具体的实现,例如:

     And the product is created successfully at the location 'blah'
    

    因为那时它们的技术性较低,您可以重复使用这些步骤来驱动测试,这些测试在您的 API 层和 UI 层进行测试,只需替换用于绑定到这些步骤的步骤实现即可。

    事实上,我可能会合并你的 2 个Then 步骤或者有这个:

    Then product 'abcdefg' is created successfully
    And the created product is available at the location 'blah'
    

    因为我不确定你可以在做什么检查

    then product is created
    

    这在

    中也没有暗示
    And user receives status 201 and creation url
    

    【讨论】:

      猜你喜欢
      • 2020-10-11
      • 2022-07-17
      • 1970-01-01
      • 2021-08-01
      • 2012-02-09
      • 2011-01-18
      • 1970-01-01
      • 2015-12-08
      • 1970-01-01
      相关资源
      最近更新 更多