wiremock provides HTTP mocking to perform black-box testing of Rust applications that
interact with third-party APIs.
It provides mocking of HTTP responses using request matching and response templating.
Table of Contents
- How to install
- Getting started
- Test isolation
- Runtime compatibility
- Prior art
- Future evolution
- Related projects
How to install
wiremock to your development dependencies:
 # ... = "0.5"
If you are using
use ; use ; async
wiremock provides a set of matching strategies out of the box - check the
for a complete list.
Expectations can be used to verify that a side-effect has (or has not) taken place!
Expectations are automatically verified during the shutdown of each
at the end of your test. A failed verification will trigger a panic.
By default, no expectations are set on your
MockServer instance goes out of scope (e.g. the test finishes), the corresponding
HTTP server running in the background is shut down to free up the port it was using.
wiremock maintains a pool of mock servers in the background to minimise the number of
connections and the time spent starting up a new
Pooling reduces the likelihood of you having to tune your OS configurations (e.g. ulimit).
The pool is designed to be invisible: it makes your life easier and your tests faster. If you end up having to worry about it, it's a bug: open an issue!
Check the table below to see how
wiremock compares to them across the following dimensions:
- Test execution strategy (do tests have to be executed sequentially or can they be executed in parallel?);
- How many APIs can I mock in a test?
- Out-of-the-box request matchers;
- Extensible request matching (i.e. you can define your own matchers);
- Sync/Async API;
- Spying (e.g. verify that a mock has/hasn't been called in a test);
- Standalone mode (i.e. can I launch an HTTP mock server outside of a test suite?).
|Test execution strategy||How many APIs can I mock?||Out-of-the-box request matchers||Extensible request maching||API||Spying||Standalone mode|
|mockito||❌ Sequential||❌ 1||✔||❌||Sync||✔||❌|
|httpmock||✔ Parallel||✔ Unbounded||✔||✔||Async/Sync||✔||✔|
|wiremock||✔ Parallel ️||✔ Unbounded||✔||✔||Async||✔||❌|
More request matchers can be added to those provided out-of-the-box to handle common usecases.
Licensed under either of Apache License, Version 2.0 or MIT license at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.