【问题标题】:RestAssured matchers for array of strings not working as expected字符串数组的 RestAssured 匹配器未按预期工作
【发布时间】:2020-10-21 10:06:23
【问题描述】:

当我尝试匹配字符串列表时:

    public void logHeaders(List<String> headers) {
        then().body("headers", Matchers.contains(headers));
    }

我明白了:

JSON path headers don't match.
Expected: iterable containing [<[Depth Top (m), Depth Base (m), Collector No., Sample No., Analysis Type, Age Range, Comments, Method, Sample Type]>]
  Actual: [Depth Top (m), Depth Base (m), Collector No., Sample No., Analysis Type, Age Range, Comments, Method, Sample Type]

现在这对我来说似乎很匹配。我尝试了各种变体,似乎与许多问题和文章相匹配。我做错了什么?

JSON 看起来像:

{
    "id": 14900,
    "headers": [
        "Depth Top (m)",
        "Depth Base (m)",
        "Collector No.",
        "Sample No.",
        "Analysis Type",
        "Age Range",
        "Comments",
        "Method",
        "Sample Type"
    ], etc

【问题讨论】:

    标签: rest-assured hamcrest serenity-bdd


    【解决方案1】:

    啊!将列表与字符串进行比较。需要:

            then().body("headers", Matchers.contains(headers.toArray(new String[headers.size()])));
    

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多