0

We are using jMeter for regression testing. We have 2 http requests and use compare assertions to make sure results match. This works fine when response is xml or raw text. This does not work, however, when the response is a JSON object. Because JSON objects store the fields in a hash the order is not maintained, meaning the Compare Assertion's diff is different and giving us false negatives. Does anyone have any advice on how to compare the two responses to see if they are equal?

user2615862
  • 149
  • 1
  • 10
  • 1
    possible duplicate of [How to compare two different JSON response structure in java?](http://stackoverflow.com/questions/21495272/how-to-compare-two-different-json-response-structure-in-java) – olyv May 22 '14 at 18:39
  • I ended up import JSONObject and [JSONCompare](http://skyscreamer.org/JSONassert/javadoc/org/skyscreamer/jsonassert/JSONCompare.html) which is the background logic of JSONAssertion so we use that instead of Compare Assertion. Works great. – user2615862 May 23 '14 at 15:13
  • @olyv It is a very different question. We do not know the format of the json. It can be very different, so the path extractor would be almost useless unfortunately. We were able to do everything in a BeanShell Post Processor and some custom coding – user2615862 May 23 '14 at 15:19
  • Please go through the below mentioned post: - http://stackoverflow.com/questions/18562060/jmeter-extracting-fields-parsing-json-response Hope this will be help. – Zubair M Hamdani May 23 '14 at 10:32

1 Answers1

1

First of all as per official documentation on Compare Assertion:

Compare Assertion MUST NOT BE USED during load test as it consumes a lot of resources (memory and CPU). Use it only for either functional testing or during Test Plan debugging and Validation.

So please reconsider using Compare Assertion. The best candidate I can think of is JSONPath Assertion available via JMeter Plugins

See Using the XPath Extractor in JMeter guide (scroll down to Parsing JSON) for XPath to JSONPath query mappings.

Alternatively you can use combination of Size Assertion, Response Assertion and, if required, Duration Assertion which provide the same functionality but consume much less resources.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks, I ended up import JSONObject and [JSONCompare](http://skyscreamer.org/JSONassert/javadoc/org/skyscreamer/jsonassert/JSONCompare.html) which is the background logic of JSONAsserttion so we use that instead of Compare Assertion. I also was aware it says not to use Compare Assertion when load testing, but we need it when doing regression testing and we really don't care about the time (it still works pretty damn fast). – user2615862 May 23 '14 at 15:12