Using WireMock how can we verify that a request of a given url has NOT been made?

TyrionWebDev picture TyrionWebDev · Jan 24, 2018 · Viewed 10.1k times · Source

Given the following unit test, I can easily test if a request of a particular url has been made. Is there a way to do the opposite, verify that a request of a particular url has NOT been made?

i.e. verify that a request was made:

stubFor(post(urlEqualTo("/login")));

webclient.submit(testLogin);

verify(postRequestedFor(urlMatching("/login")

What I'd like to do - Verify that a request was NOT made:

stubFor(post(urlEqualTo("/login")));

webclient.submit(testLogin);

verify(postRequestedFor(urlNotMatching("/login")

Answer

best wishes picture best wishes · Jan 29, 2018

did you try

verify(exactly(0), postRequestedFor(urlEqualTo("/login")));

Basically checking if exactly 0 calls were made. To read more about it. see here