主张大动态响应 [英] Asserting Against Large Dynamic Response

查看:59
本文介绍了主张大动态响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对一个很大的响应数组进行断言,但是却不知道顺序.我有一个带有预期响应值的变量,因此可以进行一次巨型比较,但是我无法加载整个响应并将其与整个预期响应变量同时进行比较.

I have a very large response array I want to assert against, but without knowing the order. I have a variable with the expected response values so I can do a single giant comparison, but I'm unable to load the entire response and compare it with the entire expected response variable at the same time.

* def obligationsQuery = Java.type("tests.account.sql.Obligations").getObligations(division, account)
    * def getObligations = db.readRows(obligationsQuery)

    Given path "account", "v1", "accounts", systemId, "obligations"
      And header api-key = gatewayKey
    When method GET
    Then status 200
      And match $.data != null
      And match $.data[*].transactionType contains any "<transactionTypeResponse>"
      And match $.data[*] contains only getObligations

    Examples:
      | description | transactionType | transactionTypeResponse |
      | Invoice     | 001             | invoice

我得到的错误是:

get_obligations_collection.feature:49 - path: $.data[*][*], actual: [{"object1"}, {"object2"}, {"etc"}], expected: {"object1"}, reason: actual value does not contain expected

我也尝试过: And match each $.data[*] contains only getObligations 但随后我得到了:

I've also tried: And match each $.data[*] contains only getObligations But then I get:

get_obligations_collection.feature:49 - path: $[0], actual: [{"object1"}, expected: [{"object1"}, {"object2"}, {"etc"}, reason: actual value is not list-like

推荐答案

我假设contains only将显示变量的完整值,但是很聪明,它仅显示与api响应对象不匹配的对象.能够通过更简单的断言来验证这一点,然后检查错误消息,发现ID缺少API添加的填充,而DB却没有.

I assumed that contains only would show the complete value of my variable, but smartly, it only shows the object that fails to match the api response object. Was able to verify that through a simpler assert, and then checking the error message saw that an ID was missing padding that the API adds, but the DB does not.

和往常一样,只需更仔细地查看返回的数据即可提供简单的解释.

As usual, just looking more closely at the data returned provides a simple explanation.

这篇关于主张大动态响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆