小黄瓜,如何编写具有可选给定步骤的方案?

时间:2018-09-29 23:10:28

标签: syntax gherkin

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

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

这对吗?

1 个答案:

答案 0 :(得分:0)

我将其分为多情景,因为每种情景都应测试一件事。

此外,您应该始终具有“何时”步骤。给定是前提,但并非总是需要,何时是一项行动,然后是该行动的预期结果。如果没有“何时”步骤,则表示您无所事事的预期结果?

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

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