Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking in Rust #120

Open
peter-lyons-kehl opened this issue Mar 20, 2024 · 2 comments
Open

Mocking in Rust #120

peter-lyons-kehl opened this issue Mar 20, 2024 · 2 comments

Comments

@peter-lyons-kehl
Copy link

peter-lyons-kehl commented Mar 20, 2024

Thank you for blessed-rs Nico.

Suggest adding an entry on Mockall, with 3: links:

  1. Comparison to other ways of mocking (in Rust) https://asomers.github.io/mock_shootout,
  2. the crate itself: mockall https://docs.rs/mockall/latest/mockall, and
  3. its sister crate mockall_double https://docs.rs/mockall_double/latest/mockall_double/index.html.

Suggest adding a new section "Mocking". Of course, up to you where to put it/what to call it. But, I don't think it fits under current Tooling > Testing, since it's not really a (shell) tool.

(I may have one more, separate, crate to add.)

@musjj
Copy link

musjj commented Oct 8, 2024

There's also https://github.com/nrxus/faux, which is great for mocking structs with multiple impl blocks spread across modules.

#[faux::create]
pub struct MyStruct {}

#[faux::methods]
impl MyStruct {
    pub fn three(&self) -> i32 {
        3
    }
}

mod foo_inner {
    use super::MyStruct;

    #[faux::methods(path = "super")]
    impl MyStruct {
        pub fn four(&self) -> i32 {
            self.three() + 1
        }
    }
}

AFAIK, this is not possible with mockall.

@djc
Copy link
Collaborator

djc commented Oct 8, 2024

Would be good to get some recent download numbers in here for the different crates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants