skyscreamer / JSONassert

Write JSON unit tests in less code. Great for testing REST interfaces.
http://jsonassert.skyscreamer.org
Apache License 2.0
992 stars 197 forks source link

Provide a "formatted as string" comparison mode #174

Open digulla opened 1 year ago

digulla commented 1 year ago

I often need to compare the output of some REST API endpoint against a "known correct result" file.

This allows me to share the file with business, QAs and customers to get early feedback. It also helps them to keep track of changes since they get to see the current result without having to deploy and run the application.

For this to be efficient, I need a way to update the file when the output changes.

With the current implementation of JSONassert, this isn't efficient since I have to parse the error message myself, find the location in the file and then copy&paste every change myself.

My approach would be much more efficient if JSONassert would format both JSON trees into strings and then would call assertEquals() on them. JUnit handles this with a special ComparisonFailure which will allow the IDE to show a textual diff. That way, I can see all difference at once and compare them side by side. If the actual output looks correct, I can simply "Select All" and paste the new content into the file.