Hi there,
I’ve spent the last two weeks getting myself familiar with Gatling and I have to say it seems like a very powerful tool. The documentation is very clear and it really helped me in getting to grips with using it. However, I’ve hit a bump in my understanding and I haven’t been able to find the answer anywhere on the web. I’m finding verification very hard. For example, I’ve found many sources that mention that you are able to assert that the content of a JSON response is as expected, but I can’t find a clear example and trial and error is getting me nowhere.
Basically, my JSON response looks like this:
{
“Before”: {
“Overall”: {
“A”: 3031080.3216904188,
“B”: 9527056.329065748,
“C”: 11439447.561616555
}
},
“After”: {
“Overall”: {
“A”: 3030423.469630083,
“B”: 9509912.047610778,
“C”: 1142233.583366325
}
},
“Change”: {
“Overall”: {
“A”: -656.8520603356883,
“B”: -17111.727953303605,
“C”: -17144.281454969198
}
}
}
I have tried the following for my scenario:
val expectedJSON = Jackson.parse(getClass.getResourceAsStream("/whatIfOutputs.json"), UTF_8)
val scnHSVaR =
exec(http(“WhatIf”)
.post("/whatif")
.header(“Content-Type”, “application/json”)
.body(StringBody("${json}"))
.check(bodyString.transform(Jackson.parse).is(expectedJSON))
).pause(1)
which works for the most part, but due to the accuracy of 16 significant figures it sometimes fails due to rounding at this level. In other testing, I have been able to introduce an acceptable epsilon to use for checking. I can’t seem to find a way to compare these to my expected values even as doubles, without even considering the acceptable precision. I tried extracting them using jsonPath, but even then I’m unsure how to convert the result to a double for comparison or how to read and store the expected values from a file to a list.
Where am I going wrong? Is anyone able to provide a basic example of this nature, or point me in the right direction?
Sorry for the long and potentially simple question, I’m just finding that even after reading everything I can find on the subject that there’s a significant knowledge gap here for me. Any help on this is greatly appreciated.