It would be nice to be able to fail a test with a clear diff between the expected and actual request body sent to a mock.
Use case: I'm mocking a third-party XML-based API and want to verify that all requests to it contain the expected data. My mocks currently have a MethodExactMatcher, PathExactMatcher and BodyExactMatcher so they only respond when the exact expected API call is done. For example:
The drawback of this approach is that when the actual request body contains a small error - the most common place for mistakes - a test fails with a 404 Not Found response because the BodyExactMatcher returns false. Those failures are a bit cumbersome to debug, having to enable debug logging so my code logs sent messages and rerun the test. It would be much nicer when a test failed with a clear diff between the expected and actual request body.
Is there a way to create such behavior with the current wiremock APIs? As far as I can see a custom matcher cannot report errors, and there's no way to add custom expectations either.
I don't believe this is possible given the current API, but it'd definitely be a significant improvement in ergonomics.
I'll think about a mechanism to make that feasible 🤔
It would be nice to be able to fail a test with a clear diff between the expected and actual request body sent to a mock.
Use case: I'm mocking a third-party XML-based API and want to verify that all requests to it contain the expected data. My mocks currently have a
MethodExactMatcher
,PathExactMatcher
andBodyExactMatcher
so they only respond when the exact expected API call is done. For example:The drawback of this approach is that when the actual request body contains a small error - the most common place for mistakes - a test fails with a 404 Not Found response because the
BodyExactMatcher
returns false. Those failures are a bit cumbersome to debug, having to enable debug logging so my code logs sent messages and rerun the test. It would be much nicer when a test failed with a clear diff between the expected and actual request body.Is there a way to create such behavior with the current wiremock APIs? As far as I can see a custom matcher cannot report errors, and there's no way to add custom expectations either.