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

customization of failure message #234

Closed
adrian-herscu opened this issue Sep 25, 2016 · 1 comment
Closed

customization of failure message #234

adrian-herscu opened this issue Sep 25, 2016 · 1 comment
Assignees
Milestone

Comments

@adrian-herscu
Copy link

We are required to verify multiple properties of complex objects.
One way to do this is within a "then" step to run a loop -- like this:

    public SELF the_response_matches(
        @JsonAssertionsFormatter.Annotation final Iterable<JsonAssertion> expectedContents) {
         val jsonVerifier = JsonAssert.with(responseContent.get());
         for (val pair : expectedContents) {
             if (null == pair.getValue()) {
                 jsonVerifier.assertNotDefined(pair.getKey());
             } else {
                 jsonVerifier.assertThat(pair.getKey(), pair.getValue());
             }
         }
        return self();
    }

The issue with this approach is that it stops evaluating further assertions upon first failed assertion. Hence, if someone tries to fix the test, then he has to run it multiple times until all properties are as they should be.

Another way would be to just write one @Test method per property. The downside of this is the amount of extra code.

It would be much nicer if we could accumulate the AssertionErrors into one AssertionError and throw it.

While running in an IDE the failure message appears quite nice:

java.lang.AssertionError: 1) JSON path [$.updateProductResponses[0].listability.descriptionOk] doesn't match.
Expected:
<false>
Actual:
true;
2) JSON path [$.updateProductResponses[0].listability.imageOk] doesn't match.
Expected:
<false>
Actual:
true

But, in the JGiven Report it is rendered into one continuous line. I tried adding CRLFs,
`s -- nothing helped :(

FAILED: java.lang.AssertionError: 1) JSON path [$.updateProductResponses[0].listability.descriptionOk] doesn't match. Expected: <false> Actual: true; 2) JSON path [$.updateProductResponses[0].listability.imageOk] doesn't match. Expected: <false> Actual: true

Is there some way to customize failure messages in the JGiven Report?

@janschaefer
Copy link
Contributor

Ok. It might be that the newlines must be replaced with HTML
tags in the report. I will have a look.

@janschaefer janschaefer self-assigned this Sep 26, 2016
@janschaefer janschaefer modified the milestones: v0.13.0, v0.12.2 Oct 8, 2016
@janschaefer janschaefer modified the milestones: v0.13.0, v0.12.2 Oct 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants