OpenFeign/feign · error · VerificationAssertionError
Wanted: ' ' but never invoked! Got
Error message
Wanted: '%s' but never invoked! Got: %s
What it means
verifyTimes(HttpMethod, String, times) builds a RequestKey from method and url and looks it up in the recorded requests map. If no request with exactly that method and url was ever recorded, a VerificationAssertionError is thrown listing the keys that were actually invoked. This is a 'wanted invocation never happened' verification failure.
Solutions
- Ensure the request was actually sent before verifying (check earlier test steps/exceptions)
- Make the method and url in verifyTimes exactly match what the client sends (path, query params)
- Inspect the 'Got:' list in the message to find the recorded key and use it
- If the request should not happen at all, use verifyNever instead
Example fix
// before mockClient.verifyTimes(HttpMethod.GET, "/api/users", 1); // never invoked // after mockClient.verifyTimes(HttpMethod.GET, "/api/v1/users", 1); // match actual request
Defensive patterns
Strategy: try-catch
Validate before calling
// Check the key exists before verifying:
RequestKey key = RequestKey.builder(method, url).build();
boolean invoked = mockClient.verifyTimes(method, url, 1) != null; // or track via verifyNever first
if (!invoked) { /* handle */ } Try / catch
try {
mockClient.verifyOne(HttpMethod.GET, "/api/users");
} catch (VerificationAssertionError e) {
fail("Expected request never invoked. Recorded: " + e.getMessage());
} Prevention
- Copy the exact method/url from the client contract into verify calls
- Always send the request before verifying it
- Read the 'Got:' list in the message to align your key
When it happens
Trigger: mockClient.verifyTimes(method, url, n>0) (or verifyOne) where requests map contains no entry whose RequestKey equals the built method/url key.
Common situations: Typo or wrong path in the verify call; request was never sent because an earlier mock/test failed; request used different query string or base URL than the verify key; sequential mode aborted before sending it.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- times must be a non negative number
- Wanted: ' ' to be invoked: ' ' times but got: ' '!
- Do not wanted: ' ' but was invoked!
- Received excessive request
- Expected: , but was
AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10).
Data as JSON: /api/errors/ff57aaaed6604100.
Report an issue: GitHub.
Appendix: source
Thrown at mock/src/main/java/feign/mock/MockClient.java:257
}
public Request verifyOne(RequestKey requestKey) {
return verifyTimes(requestKey, 1).get(0);
}
public List<Request> verifyTimes(final HttpMethod method, final String url, final int times) {
if (times < 0) {
throw new IllegalArgumentException("times must be a non negative number");
}
if (times == 0) {
verifyNever(method, url);
return Collections.emptyList();
}
RequestKey requestKey = RequestKey.builder(method, url).build();
if (!requests.containsKey(requestKey)) {
throw new VerificationAssertionError(
"Wanted: '%s' but never invoked! Got: %s", requestKey, requests.keySet());
}
List<Request> result = requests.get(requestKey);
if (result.size() != times) {
throw new VerificationAssertionError(
"Wanted: '%s' to be invoked: '%s' times but got: '%s'!",
requestKey, times, result.size());
}
return result;
}
public List<Request> verifyTimes(RequestKey requestKey, final int times) {
if (times < 0) {
throw new IllegalArgumentException("times must be a non negative number");
}
View on GitHub (pinned to e2a1e27560)