Closed foaw closed 10 months ago
Hi, can you please share some example, where the error message is not sufficient?
Hi there! I wouldn't call it insufficient, as it gives exactly what isn't adding up—all paths where the values are different, and the values themselves at the paths.
The thing is, from "X is Y; expected Z" I can't figure out why. This is where I need the entire JSON at hand, from which I could learn object I'm dealing with, what identifier it has, what other properties, etc.
At the moment, the best alternative I was able to come up with, is to include some means of identification into the assertion messages, which isn't ideal though. Although this way I can find the expected JSON, there is still no information as to what the actual value turned out to be.
So it's not insufficient for comparing data, where it does a great job at giving you where the values have diverged. It would just be handy if this was included too. I can see that not all people may want to have this behaviour by default, and so I'm only suggesting to provide the feature and give the ability to opt-in to this, without making it the default.
By the way, after filing this issue, I though it'd also be cool if the stacktrace wasn't repeated for every difference, as it's the same stacktrace anyway. Should I open another issue for this, or can these two be merged, if we say that this one isn't about printing compared data, but changing the report format in general?
Looked once again into the code. I guess I wasn't as attentive yesterday—it does already print what I'm proposing in net.javacrumbs.jsonunit.core.internal.Diff#logDifferences
.
Although it only does so at the DEBUG
level and unformatted. Also, it also doesn't follow the format IntelliJ IDEA expects, so it's kind of hard to notice, much less compare with the unaided eye.
Let me know, if you now understand what I was talking about. I can probably try to explain with a complete test report as I think it'd be better.
Updated: Can confirm it's possible to do it on my side, catching MultipleFailuresError
and extracting the necessary information from JsonUnit's AssertionFailedError
. This probably isn't ideal though, as it'd practically mean I'd have to write a wrapper around JsonUnit...
Hi, I understand, but honestly, I do not know how to implement it.
Is your feature request related to a problem? Please describe. In my experience, it's so happened that I mostly send off big JSONs, looking all undistinguishably from one another. To even tell where an assertion has failed, or rather on what data, I added a custom message. Then I go to the place where the data is defined and look for it.
The last part, or in some cases even writing assertion descriptions, can be avoided. If I had just the full JSONs of compared data, it would already be enough sometimes.
Describe the solution you'd like. The data compared can be included in the exception message at the top, as is the case with structural differences. In their messages, they have the expected and the actual data, but only rooted at the level where there were unmatching keys or values.
Describe alternatives you've considered. None. I don't think there are any. I looked in the source code, and it seems like no functionality is provided for this, either via SPI, options, or any other levers.