Popularity
3.9
Declining
Activity
0.0
Stable
226
6
5

Programming language: Rust
License: MIT License
Tags: Development Tools     Testing     Test-Driven     Mock    
Latest version: v0.9.5

Mockiato alternatives and similar packages

Based on the "Testing" category.
Alternatively, view Mockiato alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Mockiato or a related project?

Add another 'Testing' Package

README

Mockiato

Build Status Latest Version Documentation dependency status [Changelog](changelog.md)

A strict, yet friendly mocking library for Rust 2018

⚠️ Disclaimer for working with stable rust

Mockiato relies on the unstable proc_macro_diagnostics API to print helpful messages and the unstable specialization feature to be able to print expected calls.

Mocks work as expected on stable rust, but diagnostics are very limited.
We recommend re-running failing tests using nighly rust in order to pin-point the issue.

Quickstart

#[cfg(test)]
use mockiato::mockable;

#[cfg_attr(test, mockable)]
trait Greeter {
    fn greet(&self, name: &str) -> String;
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn greet_the_world() {
        let mut greeter = GreeterMock::new();

        greeter
            .expect_greet(|arg| arg.partial_eq("world"))
            .times(1..2)
            .returns(String::from("Hello world"));

        assert_eq!("Hello world", greeter.greet("world"));
    }
}

Trait Bounds

Trait bounds are currently not supported meaning that the supertraits will not be implemented for mocks.

The following traits are always implemented for mocks:

  • Debug
    Example: [cargo run --example debug](./examples/debug.rs)
  • Clone
    Example: [cargo test --example clone](./examples/clone.rs)
  • Default
    Example: [cargo test --example default](./examples/default.rs)

Downcasting

An example of how to use downcasting with mockiato can be found in the [downcasting](./examples/downcasting.rs) example.

Contributing

Enable debug impls in codegen

cargo test --features mockiato-codegen/debug-impls