Mock/not-mock response on a per request basis in Integration test.

52 views
Skip to first unread message

sumit singhal

unread,
Feb 5, 2021, 7:41:54 AM2/5/21
to wiremock-user

Hi Team,

I am writing Integration tests. I have a need where for a positive test case request hit an actual service and receive the response. But for a negative test case I must get the mocked response.

I am curious to understand if there is a way that I can mock/not-mock the request on a per configuration basis. Like for example if request accepts email address in request and I provide

  1. "inv...@email.com" - response from wire-mock must be a mocked response.
  2. "va...@email.com" - mocking must not happen but rather it must hit the actual server to get the response. may be via redirecting or calling the actual service and responding the response to the caller.

Regards,

thilmano_wiremockuser

unread,
Feb 5, 2021, 7:59:31 AM2/5/21
to wiremock-user

You can tryout "proxyBaseUrl" feature in Wiremock. This would help you implement the Live Invocation

Tom Akehurst

unread,
Feb 5, 2021, 11:43:39 AM2/5/21
to wiremock-user
You'd need 2 stubs for this:
1) A higher priority (e.g. 5) stub that has a matchesJsonPath body pattern  with an expression matching the email address field you've specified. This should return the negative response status and body you require.
2) A lower priority (e.g. 8) stub that returns a proxy response via the proxyBaseUrl field. In most cases this stub should be made to match any URL and method.

Reply all
Reply to author
Forward
0 new messages