代码之家  ›  专栏  ›  技术社区  ›  physicsboy

黄瓜/小黄瓜-是否可以将“When”术语放在“Background”中?

  •  0
  • physicsboy  · 技术社区  · 6 年前

    我的黄瓜/小黄瓜测试包括一些基本的创建和删除,但是第一个场景包括一个过程,这是后续场景的先决条件。

    例如: 如果我们有一辆新车,它的内容在某种数组中找到(因为它是新的,所以最初是空的)

    Scenario: Adding an item to the car
        Given I have bought a new car
        When I add fluffy dice to the mirror
        Then There should be fluffy dice found in the car
    
    Scenario: Removing an item from the car
        Given I have bought a new car
        When I add fluffy dice to the mirror
            And I remove fluffy dice from the mirror
        Then There should be no items found in the car
    
    Scenario: Add multiple items to the car
        Given I have bought a new car
        When I add fluffy dice to the mirror
            And I a bobble head to the dashboard
        Then there should be 2 items in the car
    

    我知道我可以抽象出这条线 Given I have bought a new car 变成一个 Background: ,但添加 When I add fluffy dice to the mirror 因为这在所有场景中都存在?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Pavel M    6 年前

    是的,这是可行的-您基本上只需更改何时和)

    Background: 
        Given I have bought a new car
        And I add fluffy dice to the mirror