簡體   English   中英

Behat Mink-無法在不知道標識符的情況下測試其余方法

[英]Behat mink - can't test rest methods without know identifier

我有一個測試其余api的問題:我無法從創建的資源獲取ID來檢查該資源是否存在。 在這里,我正在檢查id:dab2b33f-0a36-4cd6-a0d4-c175515abbab,但是每次運行“方案:添加新城市”時,我都有不同的標識符。

  Scenario: Add new city
    When I add "Content-Type" header equal to "application/json"
    And I add "Accept" header equal to "application/json"
    And I send a "POST" request to "/cities" with body:
    """
    {
      "name": "City1",
      "geo": {
        "latitude": 0,
        "longitude": 0
      }
    }
    """
    Then the response status code should be 201
    And the response should be in JSON
    And the header "Content-Type" should be equal to "application/json; charset=utf-8"

  Scenario: Delete city with existing id
    When I add "Content-Type" header equal to "application/json"
    And I add "Accept" header equal to "application/json"
    And I send a "DELETE" request to "/cities/dab2b33f-0a36-4cd6-a0d4-c175515abbab"
    Then the response status code should be 204

有誰知道如何從上次響應中獲取ID並在第二種情況下進行操作?

這些場景是並且應該是獨立的,除非您定義自己的步驟並獨立地使用靜態變量/方法將其保存在數據類中,否則我認為您不能在第二個場景中使用第一個場景中的值然后閱讀第二篇。

最后,我受到https://github.com/api-platform/core/blob/master/features/main/uuid.feature的啟發,該功能可以為我的API設置標識符。 因此,它看起來像:1)我有教義的數據庫,在其中添加一些帶有硬編碼標識符的記錄來管理測試中所需的依賴項2)我在測試中使用了這些標識符3)我使用IDENTIFIER創建了一些資源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM