NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io
crates.io, #1304 most downloaded on crates.io
HTTP mocking for Rust.
Latest stable
1.7.2
Last release 9 months ago
02 Feb 2026
Release timing varies
gaps range from 9 days to 9 months
Nearly every release is documented
notes for 60 of the last 60 stable releases
2 versions withdrawn
withdrawn after publishing
11 years old
77 releases · first in 2016
Drag across the ruler to compare, or tap a release to open it.
Update to reqwest 0.13 by @tottoto in https://github.com/lipanski/mockito/pull/223
Add headers method to Request struct by @gustavomedeiross in https://github.com/lipanski/mockito/pull/220
Your coding agent can read these notes before it upgrades. Set up the MCP server →
1.7.1
Compare
- Make parking_lot optional - Update rand crate to v0.9 - Allow colored crate v3 Thanks to @tottoto @nerodono
parking_lot optionalrand crate to v0.9colored crate v3Thanks to @tottoto @nerodono
Added Mock::with_header_from_request allowing you to set the header dynamically by using a closure which exposes the Request object
Mock::with_header_from_request allowing you to set the header dynamically by using a closure which exposes the Request objectThanks to @alex-kattathra-johnson
Introduced Mock::match_request which exposes the Request object via a closure and can be used to build custom matchers
Mock::match_request which exposes the Request object via a closure and can be used to build custom matchers- [Breaking] Upgrade to hyper v1 Thanks to @tottoto
Thanks to @tottoto
[Breaking] Bump minimum supported Rust version to 1.70 and revert version constraints on the colored crate
colored crateFixed a bug where Semaphore::const_new wasn't available on Tokio < 1.30 because of the missing Tokio parking_lot feature flag
Semaphore::const_new wasn't available on Tokio < 1.30 because of the missing Tokio parking_lot feature flagfutures crate (aside from futures-core)Thanks to @tottoto
Introduced Server::new_with_opts, Server::new_with_opts_async and the ServerOpts struct to allow configuring the server host, port and enabling auto-a
Server::new_with_opts, Server::new_with_opts_async and the ServerOpts struct to allow configuring the server host, port and enabling auto-asserts (see next item)assert_on_drop server option that allows you to automatically call assert() whenever your mocks go out of scope (defaults to false)Server::socket_address() to return the raw server SocketAddrhyper::header::HeaderValue as a match_header() valueThanks to @andrewtoth @alexander-jackson
[Breaking] The minimum supported Rust version was bumped to 1.68.0
mac_os targets to prevent hitting the file descriptor limitThanks to @kornelski
Ensure with_chunked_body supports streaming responses (as opposed to writing the entire buffer in one go)
with_chunked_body supports streaming responses (as opposed to writing the entire buffer in one go)Thanks to @kornelski
Enable the server pool properly and set the server pool size to 50
Print the query part in last unmatched request diffs.
Server::reset_async has been deprecated in favour of Server::reset since the former doesn't have an async implementation any more.
futures::future::join_all would block the server pool.Server::reset_async has been deprecated in favour of Server::reset since the former doesn't have an async implementation any more.[Breaking] Mock::with_body_from_fn was renamed to Mock::with_chunked_body - the former is still supported with a deprecation warning
:balloon: 7 years and 63 releases later, it's finally time for the 1.0 :balloon:
Mock::with_body_from_fn was renamed to Mock::with_chunked_body - the former is still supported with a deprecation warningMock::remove and Mock::remove_async methods to remove mocks on demandFor a list of all the changes please check the release log.
Legacy API:
let m1 = mockito::mock("GET", "/hello").with_body("hello").create();
let m2 = mockito::mock("GET", "/bye").with_body("bye").create();
// Use one of these to configure your client
let host = mockito:server_address();
let url = mockito::server_url();
New API:
let mut server = mockito::Server::new();
server.mock("GET", "/hello").with_body("hello").create();
server.mock("GET", "/bye").with_body("bye").create();
// Use one of these to configure your client
let host = server.host_with_port();
let url = server.url();
If you can't migrate to the new API in one go, consider using version 0.32.5, which supports both the legacy API as well as the new API.
In order to write async tests, you'll need to use the _async methods:
Server::new_asyncMock::create_asyncMock::assert_asyncMock::matched_asyncMock::remove_asyncServer::reset_async...otherwise your tests will not compile and you'll see this error:
Cannot block the current thread from within a runtime. This happens because a function attempted
to block the current thread while the thread is being used to drive asynchronous tasks.
Example:
#[tokio::test]
async fn test_simple_route_mock_async() {
let mut server = Server::new_async().await;
let m1 = server.mock("GET", "/a").with_body("aaa").create_async().await;
let m2 = server.mock("GET", "/b").with_body("bbb").create_async().await;
let (m1, m2) = futures::join!(m1, m2);
// You can use `Mock::assert_async` to verify that your mock was called
// m1.assert_async().await;
// m2.assert_async().await;
}
Implement and enable a new server pool and get rid of the deadpool dependency
Arc (more reliable in this case)Introduce Mock::with_body_from_request which allows setting the response body dynamically, based on the Request object
Mock::with_body_from_request which allows setting the response body dynamically, based on the Request objectMutex with an RwLockVarious fixes addressing hanging/flickering tests
Server::new and Server::new_async now return a ServerGuard object which dereferences to Server - this is only relevant if you need to assign a type to your serverPrevent the Mock destructor from hanging in some cases
_async methodsNothing published for this version
This version will be backwards compatible with the previous version, but deprecation warnings have been introduced and you are encouraged to migrate,…
This is a major re-write, introducing a bunch of long awaited features:
[Breaking] The minimum supported Rust version was bumped to 1.65.0
Tests can now run in parallel as long as you use the new mockito::Server API:
let mut server = mockito::Server::new();
let mock = server.mock("GET", "/").with_body("test").create();
// Use one of these to configure your client
let host = server.host_with_port();
let url = server.url();
You can run multiple servers/hosts at the same time:
let mut twitter = mockito::Server::new();
let twitter_mock = server.mock("GET", "/api").with_body("tweet").create();
let twitter_host = twitter.host_with_port();
let mut github = mockito::Server::new();
let github_mock = server.mock("GET", "/api").with_body("repo").create();
let github_host = github.host_with_port();
Support for HTTP2
An async interface for all actions (though the sync interface is also available):
let mut server = Server::new_async().await;
let mock = s
.mock("GET", "/hello")
.with_body("world")
.create_async()
.await;
mock.assert_async().await;
The backend has been rewritten to use Hyper
This version will be backwards compatible with the previous version, but deprecation warnings have been introduced and you are encouraged to migrate, since the old API still requires running tests sequentially. Migrating to the new API is quite straighforward:
Legacy API:
let m = mockito::mock("GET", "/").with_body("hello").create();
// Use one of these to configure your client
let host = mockito:server_address();
let url = mockito::server_url();
New API:
let mut server = mockito::Server::new();
let m = sever.mock("GET", "/").with_body("hello").create();
// Use one of these to configure your client
let host = server.host_with_port();
let url = server.url();
In order to write async tests, you'll need to use the _async methods:
Server::new_asyncMock::create_asyncMock::assert_asyncMock::matched_asyncServer::reset_async...otherwise your tests will not compile and you'll see this error: Cannot start a runtime from within a runtime.
When using tokio, prefer the single-threaded runtime over the multi-threaded one.
Example:
#[tokio::test]
async fn test_simple_route_mock_async() {
let mut server = Server::new_async().await;
let m1 = server.mock("GET", "/a").with_body("aaa").create_async().await;
let m2 = server.mock("GET", "/b").with_body("bbb").create_async().await;
let (m1, m2) = futures::join!(m1, m2);
// You can use `Mock::assert_async` to verify that your mock was called
// m1.assert_async().await;
// m2.assert_async().await;
}
Prevent tests from blocking endlessly when encountering HTTP parsing errors.
Thanks to @chantra
Replaced the unmaintained difference crate with the similar crate.
Thanks to @ameliabradley
Update the assert-json-diff dependency.
assert-json-diff dependency.Thanks to @davidpdrsn
[Breaking] The minimum supported Rust version was bumped to 1.42
rand, colored, serde_urlencoded, env_loggerThanks to @kornelski and @davidpdrsn
Introduced the Matcher::Binary variant for matching binary content.
Matcher::Binary variant for matching binary content.Thanks to @torrefatto
Added a Mock#matched() as a soft way of checking that a Mock, as opposed to the Mock#assert() method, which panics.
Mock#matched() as a soft way of checking that a Mock, as opposed to the Mock#assert() method, which panics.Thanks @max-b
[Breaking] Increased the minimum supported Rust version to 1.36.0.
Fixed and issue where spaces encoded as + wouldn't be interpreted properly by Matcher::UrlEncoded.
+ wouldn't be interpreted properly by Matcher::UrlEncoded.Thanks to @cakekindel
Improve error messages and the String representation of mocks, especially when it comes to their AllOf and AnyOf parts.
AllOf and AnyOf parts.Thanks to @max-b
When creating multiple mocks that match the same request, the last defined mock should be the one matched forever, once the all other mocks have reach
You can provide different mocks (and especially mock responses) for subsequent requests to the same endpoint. See https://github.com/lipanski/mockito/
501 Mock Not Implemented response now comes with a content-length: 0 header, to prevent some clients from hanging.Thanks to @xneomac
Fix compatibility with the assert-json-diff library (version 1.0.3)
assert-json-diff library (version 1.0.3)Fix a problem regarding the assert-json-diff library.
assert-json-diff library.Thanks to @vldm
Set the connection: close header on all responses delivered by Mockito as this is the default behaviour at the moment.
connection: close header on all responses delivered by Mockito as this is the default behaviour at the moment.[Breaking] Increased the minimum supported Rust toolchain to 1.35.0.
Mock#expect_at_least and Mock#expect_at_most functions to be used together with Mock#assert.cargo fmt formatting as part of CI.Thanks to @kornelski @xneomac @thomasetter
Fixed an issue regarding usage of the AnyOf matcher for the path/query parts within a mock call.
Introduced a feature flag color (enabled by default), that controls whether the output is coloured and, more importantly, whether the colored crate is
color (enabled by default), that controls whether the output is coloured and, more importantly, whether the colored crate is required.Thanks to @repi
Introduced the Matcher::PartialJson and Matcher::PartialJsonString variants to match a JSON String partially (inclusion).
Matcher::PartialJson and Matcher::PartialJsonString variants to match a JSON String partially (inclusion).Thanks to @matteosister
Introduced the Mock#with_body_from_fn function, which allows generating the response body programmatically.
Mock#with_body_from_fn function, which allows generating the response body programmatically.Thanks to @kornelski
[Breaking] The minimum supported Rust version was increased to 1.32, after upgrading the rand crate dependency to 0.7.0.
Matcher::AllOf, which can be used to check a set of matchers in conjunction. It works in a similar way to the existing Matcher::AnyOf.Matcher::UrlEncoded to match key/value pairs in URL-encoded strings.Mock#match_query to be able to match the URL query part distinctly from the path. The function supports all known matchers but works best with Matcher::UrlEncoded. The old behaviour of matching the query as part of the path argument in a mock call has been preserved, but using Mock#match_query has the effect of overriding that.:balloon: :balloon: :balloon:
Exclude CI & other unrelated files from packaging and turn the binary into an example.
Thanks to @ignatenkobrain
Support Transfer-Encoding: chunked.
Transfer-Encoding: chunked.Thanks to @loyd
Support HTTP/1.0 and working without Content-Length.
Content-Length.Content-Length response header and skipping the response body entirely in the particular case of HEAD requests.Thanks to @loyd
Fixed several issues regarding request parsing.
Thanks to @saks
[Breaking] The mock sever will get a dynamically assigned port, though it will try port 1234 first. You will need to change the way you set the server
mockito::SERVER_URL or mockito::SERVER_ADDRESS to mockito::server_url() or mockito::server_address().Thanks to @kornelski
Refactored the server checks - thanks to @kornelski
[Breaking] Fully deprecated Matcher::JSON, in favour of Matcher::Json.
~~This is the release candidate for the 1.0.0 :tada: ~~
Matcher::JSON, in favour of Matcher::Json.Thanks to @sterlingjensen, @otavio, @galaxie and @mikrostew
Introduced the Matcher::AnyOf variant, which takes a vector of matchers as argument.
Matcher::AnyOf variant, which takes a vector of matchers as argument.Mock::with_body and Mock::with_body_from_file functions now support binary content.Via header) are checked over all values. The previous implementation was looking only for the first found header value.501 Not Implemented to 501 Mock Not Found.422 Unprocessable Entity to 422 Mock Error.Thanks to @kornelski
Introduced a coloured diff, comparing the expected request with the last unmatched request whenver the Mock::assert() method fails. Closes https://git
Mock::assert() method fails. Closes https://github.com/lipanski/mockito/issues/23Renamed Matcher::JSON to Matcher::Json and introduced a deprecation warning for the old matcher.
Matcher::JsonString which works similarly to the existing Json matcher, except that it takes a String as an argument. This can be useful for test suites which don't expose serde_json methods.Matcher::JSON to Matcher::Json and introduced a deprecation warning for the old matcher.MOCKITO_DEBUG environment variable before running tests.Removed the need for running tests with --test-threads=1. Tests containing mocks will still run sequentially, but this is handled internally now. Test
--test-threads=1. Tests containing mocks will still run sequentially, but this is handled internally now. Tests that don't use mocks can be run in parallel. If you're using mocks inside doctests, please check https://github.com/lipanski/mockito/issues/36Bump the serde_json dependency to ^1.0.17, which solves the JSON matcher problems when the preserve_order feature of serde_json is enabled.
serde_json dependency to ^1.0.17, which solves the JSON matcher problems when the preserve_order feature of serde_json is enabled.Thanks to @Diggsey
Fixed compiler warnings because of useless mut.
mut.Thanks to @jean553
Introduced the Matcher::JSON variant for matching JSON request bodies.
Matcher::JSON variant for matching JSON request bodies.Thanks to @andir
Fixed a bug where tests wouldn't run without the --test-threads=1 flag any more.
--test-threads=1 flag any more.Thanks to @estin
Fixed a bug where the status *reason phrase* was missing from the server response. This was causing problems with mocking requests that went through H
Rewrote part of the internal implementation of Mockito, replacing the client/server approach with a singleton state controlled through a mutex. Long s
The Mock#assert error message now prints out the last unmatched request as well: ``` Expected 1 request(s) to:
Mock#assert error message now prints out the last unmatched request as well:Expected 1 request(s) to:
POST /users
bob
...but received 0
The last unmatched request was:
POST /users
content-length: 5
alice
Vec, instead of HashMap to solve the sorting problem once and for all./mockito.Introduced the Mock#match_body method for matching the request body by using the usual Matcher variants.
Mock#match_body method for matching the request body by using the usual Matcher variants.One column per quarter.