{"id":13502888,"url":"https://github.com/lipanski/mockito","last_synced_at":"2025-05-13T19:18:20.663Z","repository":{"id":3412720,"uuid":"49388109","full_name":"lipanski/mockito","owner":"lipanski","description":"HTTP mocking for Rust!","archived":false,"fork":false,"pushed_at":"2025-03-04T09:29:20.000Z","size":1540,"stargazers_count":731,"open_issues_count":7,"forks_count":60,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-28T10:54:58.161Z","etag":null,"topics":["http","http-mock","http-mocking","httpmock","mock","mocks","rust","test","test-framework","webmock"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lipanski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"lipanski"}},"created_at":"2016-01-10T22:18:04.000Z","updated_at":"2025-04-26T10:40:18.000Z","dependencies_parsed_at":"2023-01-13T12:29:51.302Z","dependency_job_id":"dc1e8c02-9b72-41cd-b402-7ed1f5d74c09","html_url":"https://github.com/lipanski/mockito","commit_stats":{"total_commits":342,"total_committers":34,"mean_commits":"10.058823529411764","dds":"0.38888888888888884","last_synced_commit":"9a07811955104fbe5e4f4fd4a35571bc37d06db1"},"previous_names":[],"tags_count":73,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipanski%2Fmockito","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipanski%2Fmockito/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipanski%2Fmockito/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipanski%2Fmockito/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lipanski","download_url":"https://codeload.github.com/lipanski/mockito/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254010830,"owners_count":21999004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","http-mock","http-mocking","httpmock","mock","mocks","rust","test","test-framework","webmock"],"created_at":"2024-07-31T22:02:28.495Z","updated_at":"2025-05-13T19:18:20.609Z","avatar_url":"https://github.com/lipanski.png","language":"Rust","readme":"\u003cp\u003e\n  \u003cp align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/lipanski/mockito/master/docs/logo-black.png\"\u003e\u003c/p\u003e\n  \u003cp align=\"center\"\u003e\n    \u003ca href=\"https://docs.rs/mockito\"\u003e\u003cimg src=\"https://docs.rs/mockito/badge.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://crates.io/crates/mockito\"\u003e\u003cimg src=\"https://img.shields.io/crates/v/mockito.svg\"\u003e\u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/badge/rust%20version-%3E%3D1.70.0-orange\"\u003e\n    \u003ca href=\"https://crates.io/crates/mockito\"\u003e\u003cimg src=\"https://img.shields.io/crates/d/mockito\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/lipanski/mockito/actions/workflows/tests.yml/?branch=master\"\u003e\u003cimg src=\"https://github.com/lipanski/mockito/actions/workflows/tests.yml/badge.svg?branch=master\"\u003e\u003c/a\u003e\n  \u003c/p\u003e\n  \u003cp align=\"center\"\u003e\u003cem\u003eHTTP mocking for Rust!\u003c/em\u003e\u003c/p\u003e\n\u003c/p\u003e\n\nMockito is a library for **generating and delivering HTTP mocks** in Rust. You can use it for integration testing \nor offline work. Mockito runs a local pool of HTTP servers which create, deliver and remove the mocks.\n\n## Features\n\n- Supports HTTP1/2\n- Runs your tests in parallel\n- Comes with a wide range of request matchers (Regex, JSON, query parameters etc.)\n- Checks that a mock was called (spy)\n- Mocks multiple hosts at the same time\n- Exposes sync and async interfaces\n- Prints out a colored diff of the last unmatched request in case of errors\n- Simple, intuitive API\n- An awesome logo\n\n\nThe full documentation is available at \u003chttps://docs.rs/mockito\u003e.\n\nBefore upgrading, make sure to check out the [changelog](https://github.com/lipanski/mockito/releases).\n\n## Getting Started\n\nAdd `mockito` to your `Cargo.toml` and start mocking:\n\n```rust\n#[test]\nfn test_something() {\n    // Request a new server from the pool\n    let mut server = mockito::Server::new();\n\n    // Use one of these addresses to configure your client\n    let host = server.host_with_port();\n    let url = server.url();\n\n    // Create a mock\n    let mock = server.mock(\"GET\", \"/hello\")\n      .with_status(201)\n      .with_header(\"content-type\", \"text/plain\")\n      .with_header(\"x-api-key\", \"1234\")\n      .with_body(\"world\")\n      .create();\n\n    // Any calls to GET /hello beyond this line will respond with 201, the\n    // `content-type: text/plain` header and the body \"world\".\n\n    // You can use `Mock::assert` to verify that your mock was called\n    mock.assert();\n}\n```\n\nIf `Mock::assert` fails, a colored diff of the last unmatched request is displayed:\n\n![colored-diff.png](https://raw.githubusercontent.com/lipanski/mockito/master/docs/colored-diff.png)\n\nUse **matchers** to handle requests to the same endpoint in a different way:\n\n```rust\n#[test]\nfn test_something() {\n    let mut server = mockito::Server::new();\n\n    server.mock(\"GET\", \"/greetings\")\n      .match_header(\"content-type\", \"application/json\")\n      .match_body(mockito::Matcher::PartialJsonString(\n          \"{\\\"greeting\\\": \\\"hello\\\"}\".to_string(),\n      ))\n      .with_body(\"hello json\")\n      .create();\n\n    server.mock(\"GET\", \"/greetings\")\n      .match_header(\"content-type\", \"application/text\")\n      .match_body(mockito::Matcher::Regex(\"greeting=hello\".to_string()))\n      .with_body(\"hello text\")\n      .create();\n}\n```\n\nStart **multiple servers** to simulate requests to different hosts:\n\n```rust\n#[test]\nfn test_something() {\n    let mut twitter = mockito::Server::new();\n    let mut github = mockito::Server::new();\n\n    // These mocks will be available at `twitter.url()`\n    let twitter_mock = twitter.mock(\"GET\", \"/api\").create();\n\n    // These mocks will be available at `github.url()`\n    let github_mock = github.mock(\"GET\", \"/api\").create();\n}\n```\n\nWrite **async** tests (make sure to use the `_async` methods!):\n\n```rust\n#[tokio::test]\nasync fn test_simple_route_mock_async() {\n    let mut server = Server::new_async().await;\n    let m1 = server.mock(\"GET\", \"/a\").with_body(\"aaa\").create_async().await;\n    let m2 = server.mock(\"GET\", \"/b\").with_body(\"bbb\").create_async().await;\n\n    let (m1, m2) = futures::join!(m1, m2);\n\n    // You can use `Mock::assert_async` to verify that your mock was called\n    // m1.assert_async().await;\n    // m2.assert_async().await;\n}\n```\n\nStart a **stand-alone server** on a dedicated port:\n\n```rust\nfn main() {\n    let opts = mockito::ServerOpts {\n        host: \"0.0.0.0\",\n        port: 1234,\n        ..Default::default()\n    };\n    let mut server = mockito::Server::new_with_opts(opts);\n\n    let _m = server.mock(\"GET\", \"/\").with_body(\"hello world\").create();\n\n    loop {}\n}\n```\n\n## Minimum supported Rust toolchain\n\nThe current minimum support Rust toolchain is **1.70.0**\n\n## Contribution Guidelines\n\n1. Check the existing issues and pull requests.\n2. One commit is one feature - consider squashing.\n3. Format code with `cargo fmt`.\n4. :shipit:\n\n## Development\n\n### Tests\n\nRun tests:\n\n```sh\ncargo test\n```\n\n...or run tests using a different toolchain:\n\n```sh\nrustup run --install 1.70.0 cargo test\n```\n\n...or run tests while disabling the default features (e.g. the colors):\n\n```sh\ncargo test --no-default-features\n```\n\n### Code style\n\nMockito uses [rustfmt](https://github.com/rust-lang/rustfmt) as a general code style.\n\nInstall `rustfmt`:\n\n```sh\nrustup component add rustfmt\n```\n\nFormat code:\n\n```sh\ncargo fmt\n```\n\nSome editors might provide a plugin to format your Rust code automatically.\n\n### Linter\n\nMockito uses [clippy](https://github.com/rust-lang/rust-clippy) and it should be run always on the minimum supported Rust version, in order to ensure backwards compatibility.\n\nInstall `clippy`:\n\n```sh\nrustup component add clippy\n```\n\nThe linter is always run on the minimum supported Rust version:\n\n```sh\nrustup run --install 1.70.0 cargo clippy-mockito\n```\n\n### Release\n\nRelease:\n\n```sh\ncargo publish\n```\n\n### Benchmarks\n\nInstall `rust nightly`:\n\n```sh\nrustup install nightly\n```\n\nRun benchmarks:\n\n```sh\nrustup run nightly cargo bench\n```\n","funding_links":["https://github.com/sponsors/lipanski"],"categories":["Rust","Development tools","Projects","rust","Mocking Libraries"],"sub_categories":["Testing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipanski%2Fmockito","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flipanski%2Fmockito","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipanski%2Fmockito/lists"}