Closed ymwjbxxq closed 1 year ago
You have to hold a reference to mockito::Server
and use that to create your mocks and call .url()
:
let mut server = mockito::Server::new();
server.mock("GET", "/endpoint").with_body("hello").create();
#[cfg(test)]
let uri = format!("{}/endpoint", server.url());
These days, every server can have its own URL and mocks.
See the migration instructions or the docs for more details.
@lipanski thank you but can you clarify is there any way to statically refer to the URL? If all endpoints are isolated by path (not port) couldn't it be static and parallel tests wouldn't stomp each other so long as they used different paths?
I have given up trying to find ways to do it and all of my production code has an additonal argument url_override
that allows my unit tests to inject the mock endpoint. But this hurts readability so I'm wondering if there's a cleaner way?
env vars are globally shared (so parallel tests will stomp each other), holding static reference to ServerGuard
is unsafe, running tests serially is slow... Any other ideas?
Hello all,
currently, I am using version
mockito = "0.31"
and my unit tests are passingIf I convert to v1 in this way:
I get this error:
reqwest sdk error reqwest::Error { kind: Decode, source: Error(\"EOF while parsing a value\"
Could you please help me to understand what the problem is? Do you know if I miss a configuration?
Thanks, Dan