【问题标题】:Gherkin, how to write a scenario where have optional given steps?Gherkin,如何编写一个具有可选给定步骤的场景?
【发布时间】:2018-11-07 18:55:28
【问题描述】:

我正在编写一个简单的添加项目场景。该项目具有必填字段(名称、编号、日期),该项目还具有可选字段(类别、描述)。我如何指定字段:

scenario: add item
   given name
   and  number
   and  date
   but category is not null
   and description is no null
   then save item

是这样吗?

【问题讨论】:

    标签: syntax gherkin


    【解决方案1】:

    我会将其拆分为多个场景,因为每个场景都应该测试一件事。

    此外,您应该始终有一个 When 步骤。 Given 是一个先决条件,并不总是需要,When 是一个动作,然后是该动作的预期结果。如果没有When 步骤,您是在说您有什么都不做的预期结果?

    我会将功能文件编写为如下所示:

    Feature: Add Item
        As a stock control manager
        I want to be able to add items to an inventory
        So that I have a catalogue of al items in stock
    
    Business Rules:
        - Name, number and date are mandatory data
        - category and description are optional
    
    Sceanrio: Add item witout category
        When I add an item without a category
        Then the Item will be saved
    
    Sceanrio: Add item without descritpion 
        When I add an item without a descritpion 
        Then the Item will be saved
    
    Sceanrio: Add item without name
        When I add an item without a name
        Then the item will not be saved
        And I will be informed the name is maditory
    
    Sceanrio: Add item without number
        When I add an item without a number
        Then the item will not be saved
        And I will be informed the number is maditory
    
    Sceanrio: Add item without date
        When I add an item without a date
        Then the item will not be saved
        And I will be informed the date is maditory
    

    【讨论】:

    • 为了完整起见,您可能还想添加一个包含所有数据的场景。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多