mkotsur / restito

Restito - mocking framework for testing rest clients
MIT License
227 stars 60 forks source link

proposal: more readable stack trace for big JSON payload with restito integration testing #70

Open bieli opened 6 years ago

bieli commented 6 years ago

When I try to find bug in my JSON payload in integration tests using restito it doesn't support me with clear debug process.

For example output for failed test:

    Condition failed with Exception:

    verifyHttp(restitoServer) .once(post("/endpoint"), withPostBodyContainingJson(asString(mySpecialBigPayload)))
    |          |               |    |                     |                          |        |
    |          |               |    |                     |                          |        class path resource [payload_big.json]
    |          |               |    |                     |                          {
    |          |               |    |                     |                            "id": "51abb572-c22b-11e8-b3f9-699386e0b5fe-54091516",
    |          |               |    |                     |                            "prop": "value",
    |          |               |    |                     |                            "id": [
    |          |               |    |                     |                              "54091516"
    |          |               |    |                     |                            ],

... ~500 lines of big JSON

    |          |               |    |                     com.xebialabs.restito.semantics.Condition@6d442a82
    |          |               |    com.xebialabs.restito.semantics.ConditionWithApplicables@70b57756
    |          |               java.lang.AssertionError: Expected to happen 1 time(s), but happened 0 times instead
    |          com.xebialabs.restito.server.StubServer@73101e8b
    com.xebialabs.restito.builder.verify.VerifyHttp@7361820a
        at
 ...
        Caused by:
        java.lang.AssertionError: Expected to happen 1 time(s), but happened 0 times instead
            at com.xebialabs.restito.builder.verify.VerifyHttp.times(VerifyHttp.java:58)
            at com.xebialabs.restito.builder.verify.VerifyHttp.once(VerifyHttp.java:42)

I had wrong values in two JSON properties/fields and I think searching/debugging phase problems too longer than I expected.

Ideal solution it will be suggest what is different or probably wrong.

It will be possible to add more clear output when test failed ?

mkotsur commented 6 years ago

Hi @bieli . Yes, that would be nice to have better error reporting in such cases. It's not very easy, though: conditions just return true/false without providing information about the difference. It could be possible, though, for some conditions (e.g. ones that check for equality). But then again, I'm not sure if it is useful to see the log of all not satisfied conditions. There can be too many...

But let me ask you, what do withPostBodyContainingJson and asString do? They are not part of restito afaik. Is it your custom condition?