Forum Discussion

jeffrey_crowley's avatar
jeffrey_crowley
Contributor
10 years ago

Verifying multiple values in a single JSON response

I'm new to SoapUI NG Pro and am trying to ramp up quickly to help on a current project. I see this as a common scenario and have googled and searched this forum but haven't found a good general purpose solution that I can reuse for my test cases. I did find this blog but it's 3 years old and seems overly complicated to do something this common. I'm assuming that I'm missing something simple with current functionality and am looking for a best practice to implement going forward.

 

See the attached file for a sample JSON response. I send a request and get back a response like this with multiple "things", in this case products. How would I validate all X products in a single pass?

 

I have tried the verify content assert at a high level and that works but if one property on one product is off, the whole thing fails and I have to look through a large respose to figure out exactly what is different. I would prefer to put content verification at a more granular level but that becomes tedious if I'm expecting a large number of things to check. In the simple attached example, there are 8 products each with 5 properties to check so that's 40 validations that I would have to manually create. Is there a way to do multi-select and bulk create asserts like this? I didn't see anything.

 

The other route I am exploring is data source looping but I'm not sure how to validate all 40 properties in a single pass using looping. I don't want to resend the request each time when it's not necessary.

 

Another route would be scripting. It seems that it would involve parsing a large section of the datasource (maybe Excel?) and then looping through the JSON response and comparing. That seems overly involved but I'm open to that if that's what is easiest/best in this case.

 

Any suggestions, pointers to articles, etc. would be much appreciated.

3 Replies

    • jeffrey_crowley's avatar
      jeffrey_crowley
      Contributor

      Thanks for the response. I should have mentioned that I tried this at some level. I have code that compares the top level nodes in the JSON response but some of the responses run very deep and it makes it hard to determine where exactly the actual failure is. I have actually seen this link but it doesn't mention jsonSlurper or deep compares, at least without additional libraries. Is there a particular library that you would recommend? I tried finding info on how to import a library into a groovy script and I didn't find any info... so I don't know if that means it can't be done or ???

      • nmrao's avatar
        nmrao
        Icon for Champion Level 1 rankChampion Level 1
        Yes, that only says if both actual and expected are matched or not which is crucial for automation.

        However, you want to find the details, probably you may need to implement as per the needs.