WireMock and Rust

Disclaimer: This solution page includes resources maintained by their authors outside the WireMock organization on GitHub. The info is provided as is without guarantees unless explicitly specified. Referenced projects and guidelines might be incompatible with the recent WireMock 3.x releases or the recent versions of the target technology or framework.

Please use with caution, and submit GitHub issues or pull requests to this page and referenced repositories if something is missing, broken or needs update.

wiremock-rs. Server implementation in Rust #

LukeMathWalker/wiremock-rs is an API Mock Server implementation in Rust. It provides HTTP mocking to perform black-box testing of Rust applications that interact with third-party APIs.

This project is inspired by WireMock and has the same name in the documentation, but it is not compatible with WireMock when it comes to CLI, REST API or configuration files. Please refer to its documentation for more details and guidelines.

use wiremock::{MockServer, Mock, ResponseTemplate};
use wiremock::matchers::{method, path};

async fn main() {
    // Start a background HTTP server on a random local port
    let mock_server = MockServer::start().await;

    // Arrange the behaviour of the MockServer adding a Mock:
    // when it receives a GET request on '/hello' it will respond with a 200.

    // Verify the response
    let status = surf::get(format!("{}/hello", &mock_server.uri()))
    assert_eq!(status.as_u16(), 200);


Stubr #

Stubr is an adaptation of wiremock-rs supporting existing WireMock json stubs as input. It aims at reaching feature parity with WireMock. The project also provides support for gRPC and offers Docker images.

use asserhttp::*;

async fn getting_started() {
    // run a mock server with the stub 👇
    let stubr = stubr::Stubr::start("tests/stubs/hello.json").await;
    // or use 'start_blocking' for a non-async version

    // the mock server started on a random port e.g. ''
    // so we use the stub instance 'path' (or 'uri') method to get the address back
    let uri = stubr.path("/hello");
        // (optional) use asserhttp for assertions
        .expect_body_text_eq("Hello stubr");


Testcontainers module #

We are interested in providing a Testcontainers for Rust module that would provide SDK for the official WireMock Docker images. This module is on our roadmap but have not been published yet, see wiremock/ecosystem #8. Contributions are welcome!