Ask a Question

Assert JSON response and identify outstanding items

emmanuelgalindo
Visitor

Assert JSON response and identify outstanding items

For a functional testing, a rest step relies in an API specification outlining the expected data model defined in each method, to check the response with Swagger Assertion

Also, we are using the smart assertion to check data.

 

However, is there any option that would also alert about additional objects in the response that are not described in the contract? 

For example

If response should have element

{

"a":1

}

and response is

{

"a":1,

"b":2

}

 

Both Swagger Assertion and Smart assertion will complete succesfully and we would like it to fail because "b" is not defined in the data model. 

2 REPLIES 2
nmrao
Champion Level 2

If the response keys are fixed, then you can check them from actual response keys and fail if keys are different.


Regards,
Rao.
richie
Community Hero

Hey @emmanuelgalindo 

 

unsure if I understand correctly, but if you want to assert on the non-existence of a json attribute you can do that with a json match existence assertion where path to attribute that shouldn't be present should be set to 'false'

 

gta

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
cancel
Showing results for 
Search instead for 
Did you mean: