Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show path to first mismatch on failure #110

Closed
davidje13 opened this issue May 25, 2018 · 1 comment
Closed

Show path to first mismatch on failure #110

davidje13 opened this issue May 25, 2018 · 1 comment

Comments

@davidje13
Copy link

I'm on a project where we're using JSON matching for our integration tests to check actual results against fixture files. We use the matchers with RestAssured like this:

RestAssured.when().post('url')
    .then().body(jsonEquals(myContentLoadedFromAFixture).when(IGNORING_EXTRA_FIELDS));

It works great for checking success/failure, but the debug message when failing is, frustratingly, just a copy of the entire expected vs actual JSON content, for example:

java.lang.AssertionError: 1 expectation failed.
Response body doesn't match expectation.
Expected: {
"foo": "bar",
"zig": "zag"
}

Actual: {"zig": "zag", "foo": "baz"}

Which is problematic when working with large JSON bodies.

It looks like #44 would be a full solution to this problem, but has issues of its own (how to skip past ignored fields, for example).

A simpler fix would save us a huge amount of time: as well as providing the mismatched content, also give the path to the first failure. Something like:

java.lang.AssertionError: 1 expectation failed.
Response body doesn't match expectation.
Expected: {
"foo": "bar",
"zig": "zag"
}

Actual: {"zig": "zag", "foo": "baz"}
First mismatch: $.foo

@davidje13
Copy link
Author

I did some more investigation and found that RestAssured uses its own match failure messages by default (which is where the output above is coming from). So I guess this isn't an issue to raise here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant