Skip to content

3. Comparing Responses

status_v2.jkt
name: Compare StatusV2 and StatusV1
tags: regression
requires: auth
request:
url: https://api.jikken.io/api/v2/examples/status
headers:
- header: Authorization
value: ${token}
compare:
url: https://api.jikken.io/api/v1/examples/status
response:
status: 200
ignore:
- user.lastActivity

We’ve seen how to use a variable to store a token and test an authenticated endpoint. Now let’s look at another common use case - comparing responses from different versions of the same API.

Comparing responses
compare:
url: https://api.jikken.io/api/v1/examples/status

Jikken has a built-in compare keyword to easily compare the responses of different APIs. Here, we put the URL for the endpoint that we want to compare with the request. By default, the HTTP status and body of the responses will be compared.

In this case, we have also specified a response.status of 200. When using compare, both responses will be validated against this condition. The test will only pass if the responses match each other, and they both match the specified status.

Ignoring fields
response:
status: 200
ignore:
- user.lastActivity

Let’s say in the newer version of the test status API (v2), we added a new response field that wasn’t present in v1. Naturally, this would cause the body comparison to fail.

To exclude “user.lastActivity” from the comparison, we specify that we want to ignore this field. Any ignored fields will be pruned from the JSON responses before the comparison occurs.

Next, we’ll see how to combine all of these concepts into a single multi-stage test.