CodeSandwich / Mocktopus

Mocking framework for Rust
MIT License
233 stars 20 forks source link
mock mocking mocktopus rust rust-library test testing testing-tools unit-testing

Crates.io Docs.rs Build Status

logo

Mocking framework for Rust (currently only nightly). See documentation for more.

#[mockable]
mod hello_world {
    pub fn world() -> &'static str {
        "world"
    }

    pub fn hello_world() -> String {
        format!("Hello {}!", world())
    }
}

#[test]
fn mock_test() {
    hello_world::world.mock_safe(|| MockResult::Return("mocking"));

    assert_eq!("Hello mocking!", hello_world::hello_world());
}