Каратэ: содержит функциональность - PullRequest
1 голос
/ 22 января 2020

У меня есть следующее, где я сравниваю ответы двух envs на лету. В моем случае для некоторых служб ответ json порядок элементов / массивов не является обязательным, а для некоторых - обязательным. Так что я использовал содержит, но я сомневаюсь, что какой-либо из элементов / массивов отсутствует в каком-либо из ответов, скажем, при сравнении ниже двух:

A: {
    "hotels": [
      { "roomInformation": [{ "roomPrice": 618.4 }], "totalPrice": 618.4  },
      { "roomInformation": [{ "roomPrice": 679.79}], "totalPrice": 679.79 }
    ]
  }

B:
{
    "hotels": [
      { "roomInformation": [{ "roomPrice": 618.4 }], "totalPrice": 618.4  },
      { "roomInformation": [{ "roomPrice": 680.79}], "totalPrice": 680.79 },
      { "roomInformation": [{ "roomPrice": 679.79}], "totalPrice": 679.79 }

    ]
  }

, используя приведенное ниже совпадение, каждый с contains дает положительный результат ? пожалуйста, предложите

Feature: 
Background:

Scenario: test
        * json input = read('input.json')
        * def stage= call read('A.feature') input;
        * def prod = call read('B.feature') input;      
        #* def rp = $prod[*].response
        #* def rs = $stage[*].response
    #* match rs contains rp
    #* match each $prod[*].response[*] contains $stage[*].response
    # * match each $prod[*].response[*] contains $stage[*].response.[*] 

Ответы [ 2 ]

1 голос
/ 23 января 2020

Так как порядок важен и находится в массиве / списке, проверка «равно», чем «содержит», работает как нужно:

Следующий код приводит к ошибке.

Код образца:

Feature: Validation

    Scenario:

        * def stage =
        """
        {
            "hotels": [
            { "roomInformation": [{ "roomPrice": 618.4 }], "totalPrice": 618.4  },
            { "roomInformation": [{ "roomPrice": 679.79}], "totalPrice": 679.79 }
            ]
        }
        """
        * def prod =
        """
        {
            "hotels": [
            { "roomInformation": [{ "roomPrice": 679.79}], "totalPrice": 679.79 },
            { "roomInformation": [{ "roomPrice": 618.4 }], "totalPrice": 618.4  }
            ]
        }
        """
        * match  prod == stage
        #ERROR: path: $.hotels[0], actual: {roomInformation=[{"roomPrice":679.79}], totalPrice=679.79}, expected: {roomInformation=[{"roomPrice":618.4}], totalPrice=618.4}, reason: [path: $.hotels[0].roomInformation[0], actual: {roomPrice=679.79}, expected: {roomPrice=618.4}, reason: [path: $.hotels[0].roomInformation[0].roomPrice, actual: 679.79, expected: 618.4, reason: not equal (Double)]]
1 голос
/ 23 января 2020

Ваш вопрос несколько запутан, что затрудняет ответ.

Кроме того, ваше утверждение может быть частичным списком ожидаемого целого. Используйте команду print, чтобы помочь вам отладить ее.

* def roomPrices = response.hotels[*].totalPrice
* print roomPrices
* match roomPrices contains [ 680.79, 1.00 ]
...