【问题标题】:Check for required properties with behat on POST在 POST 上使用 behat 检查所需的属性
【发布时间】:2017-02-06 06:02:31
【问题描述】:

我正在测试我的 REST API,所以我正在做这样的事情:

Scenario: Create a Task List
  Given I send a POST to tasklist with json:
  """
  {
    "creator_id" : 1,
    "title" : "Behat Test List",
    "display_order" : 7,
    "color" : 123456,
    "type": 1
  }
  """
  Then The response code should be 201

这 5 个属性都是创建任务列表所必需的。我现在需要再写五个,并省略其中一个参数,并确保响应代码是 400。这感觉就像大量的重复。这样做的正确方法是什么?

【问题讨论】:

    标签: behat gherkin


    【解决方案1】:

    尝试这样的场景大纲:

    Scenario Outline: Create a Task List
    Given I send a POST to tasklist with json:
    """<sample>"""
    Then The response code should be 201
    
    Examples:
      | sample                                                                                              |
      | { "creator_id" : 1, "title" : "Behat Test List", "display_order" : 7, "color" : 123456, "type": 1 } |
    

    【讨论】:

      猜你喜欢
      • 2020-06-09
      • 2014-05-10
      • 2022-01-21
      • 2013-09-29
      • 2011-08-24
      • 1970-01-01
      • 2020-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多