question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spurious failure with "request was unmatched by any stub matching" since upgrade to WireMock 2.9.0

See original GitHub issue

Without changing any of our own code, updating from WireMock 2.8.0 to 2.9.0 causes many tests to fail with spurious “unmatched request” errors.

Example test:

@Test
public void testAuditLogRequestHeader() throws Exception
{
    callingOurStuffHere();
    verify(postRequestedFor(urlEqualTo("/1/team/log/get_events"))
               .withHeader("Authorization", WireMock.equalTo("Bearer " + TOKEN))
               .withRequestBody(equalToJson("{}")));
}

Failure text:

com.github.tomakehurst.wiremock.client.VerificationException: A request was unmatched by any stub mapping. Request was: 

	at com.github.tomakehurst.wiremock.client.VerificationException.forUnmatchedRequests(VerificationException.java:92)
	at com.github.tomakehurst.wiremock.junit.WireMockRule.checkForUnmatchedRequests(WireMockRule.java:90)
	at com.github.tomakehurst.wiremock.junit.WireMockRule.access$000(WireMockRule.java:34)
	at com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:74)
	at com.acme.common.test.rules.BaseTestRule$1.evaluate(BaseTestRule.java:45)
	at com.acme.common.test.rules.BaseTestRule$1.evaluate(BaseTestRule.java:45)
	at com.acme.common.test.rules.BaseTestRule$1.evaluate(BaseTestRule.java:45)
	at com.acme.common.test.rules.BaseTestRule$1.evaluate(BaseTestRule.java:45)
	at com.acme.common.test.rules.BaseTestRule$1.evaluate(BaseTestRule.java:45)
	at com.acme.common.test.rules.Timeout$CustomFailOnTimeout$StatementRunner.run(Timeout.java:137)
	at java.lang.Thread.run(Thread.java:745)

The odd thing is how it doesn’t actually print out anything…

This appears to occur consistently for tests using verify(postRequestedFor(...)) but tests using stubFor(post(...)) still pass.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10

github_iconTop GitHub Comments

3reactions
tomakehurstcommented, Nov 9, 2017

OK, so you’re not actually creating any stubs here. WireMock’s default behaviour is to fail your test if you’ve made requests that it hasn’t been able to match, on the assumption that this probably means you’ve missed something. This is analogous to the approach some object mocking tools take where unexpected calls are considered errors.

Two options to fix this:

  1. Stub the call being made so that there’s something to match it (I’d consider this best practice)
  2. Disable the failure behaviour by setting failOnUnmatchedRequests to false in the rule constructor.
0reactions
hakanaicommented, Nov 13, 2017

I’ve ended up updating all the tests using verify to use stubFor instead, and they’re passing, so I’ll just close this. Thanks for the info.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spurious failure with "request was unmatched by any stub ...
Without changing any of our own code, updating from WireMock 2.8.0 to 2.9.0 causes many tests to fail with spurious "unmatched request" errors....
Read more >
Wiremock error: Request was not matched as there were no ...
com.github.tomakehurst.wiremock.client.VerificationException: A request was unmatched by any stub mapping. Closest stub mapping was: <Click ...
Read more >
Expected == Actual: error reporting problem? - Google Groups
com.github.tomakehurst.wiremock.client.VerificationException: A request was unmatched by any stub mapping. Closest stub mapping was: ...
Read more >
Verifying whether specific HTTP requests were made | WireMock
All requests received by WireMock since the last reset can be fetched, along with additional data about whether the request was matched by...
Read more >
Wiremock postrequestedfor - Marogal
By default, WireMock will use the most recently added matching stub to ... to 2.9.0 causes many tests to fail with spurious "unmatched...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found