簡體   English   中英

驗證嵌套響應體 rest 保證

[英]Validate nested response body rest assured

我知道 rest 中有很多關於驗證的信息,但不幸的是我無法找到解決我問題的確切方法。

我正在訓練驗證以下 JSON 的響應:

{
"A":[
  {
     "B":[
        {
           "C":"c",
           "D":"d"
        }
     ],
     "E":[
        {
           "F":[
              {
                 "G":"g1"   
              }
           ]
        },
        {
           "F":[
              {
                 "G":"g2"
              }
           ],
        },
        {
           "F":[]
        }
     ]
  }
],
"H": "h"
}

使用以下代碼:

 response.body("A.E.F.G", hasItems(expectedValues.get(G).toArray(new String[0])))

expectedValues.get(G) 返回 g1 和 g2 的列表。

我得到的錯誤是:

JSON path A.E.F.G doesn't match.
Expected: an array containing ["g1", "g2"]
Actual: [[[g1], [g2], []]]

我怎樣才能做到這一點?

即解決問題:

response.body("A.E.F.G.flatten()", hasItems(expectedValues.get(G).toArray(new String[0])))

暫無
暫無

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

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