Assert API response body against a baseline file (JSON) #695
Replies: 1 comment
-
About assertion, if it's not possible with built-in Feel free to reopen if needed, with a full reproducer testsuite.yml file. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it possible to assert the response body against a predefined baseline file? I have been trying different approaches to achieve this without success. I have APIs with big response objects and asserting each field individually would be a huge pain and the tests very hard to maintain. Having something that compares the whole JSON or portions of it would be really helpful.
The way I implemented it is: I have a first step of type readfile that reads the baseline file. Then in another step I execute the API call and in the assertions section I try to assert equality (either of the full body or parts of the body).
The response is identical to the baseline, however I believe somehow the data types are different. I used .result.bodyjson.bodyjson0.field ShouldEqual {{ .result.contentjson.contentjson0.field}}.
If I add these in the info section, they look identical, however the assertion fails with something like:
expected {"a", 1, "b", 1"}, got map[a:1 b:1]
It looks like comparing two different data types, although I used bodyjson and contentjson which should both have the same type.
Did anyone try and achieve this?
Beta Was this translation helpful? Give feedback.
All reactions