Reputation: 361
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")
Upvotes: 36
Views: 40000
Reputation: 2291
There response above works. For more complex asserts, WireMock Admin REST API allows retrieving all requests in the journal - GET: /__admin/requests. In your unit tests, e.g. with a Native Java library JUnit rules or with a Testcontainers module, you can:
Upvotes: 0
Reputation: 6634
verify(exactly(0), postRequestedFor(urlEqualTo("/login")));
Basically checking if exactly 0 calls were made. To read more about it. see here
Upvotes: 46