Rust has several different mocking libraries. None is clearly superior to all of the others. This project compares their feature sets, using an apples-to-apples approach. Each of several dozen features is implemented with multiple mocking libraries, if possible. The test results then show which features work with which library.
Do you need both static methods and methods that return references with non-'static lifetimes? Then you should use Mock_Derive. Or perhaps you like to derive your mocks and you need to validate call sequences? Then you should use Mockers.
Check our the handy table to find the mocking library that's right for you.
This is incredibly thorough! Thanks a lot for creating this resource.
A note on a potentially improvement: it'd be very helpful for colorblind (and even blind) users if you put some "YES" / "NO" text in the big feature comparison table. Especially given that you chose red and green
FYI, I'm continuously updating the shootout. If you want to see new additions, you should subscribe to the Github repo. I won't post every update to the forum. Today's update: not a single library is capable of mocking a Send trait.
I dropped Mock_Derive off the list, because it's fallen behind on maintenance. It no longer compiles with recent nightly toolchains. Also, double now implements Send.
I actually have a branch running on nightly for my project that has been updated to the latest syn/quote and brought up-to-date so it compiles, plus added some features I needed. It's located here https://github.com/carlosdp/mock_derive . I've been thinking of contacting the maintainer to see if I can perhaps come on as a maintainer myself and work on it, since I intend to use it for my stuff. It's super convenient.
I updated the shootout with Mocktopus. Mocktopus is unusual in that it's trait-agnostic. It works on individual functions, whether or not they're part of a trait.
I'm aware of mockito. But I'm not going to add it to the shootout because it's too different. The shootout is only concerned with mock objects. Mockito is much more specialized.
It seems to me that Mockers no longer requires a nightly compiler! It says so on GitHub and at first glance I can affirm that (having added the recent version to the Cargo.toml of a non-nightly project and successfully compiling it).
If your are still updating your very appreciated overview, this might be an occasion.
Mockall is here! None of the libraries I reviewed could satisfy all of my needs, so I wrote my own. I incorporated the best parts of Mockers and Simulacrum, and added some innovations of my own. Mockall runs on stable Rust and uses no unsafe code at all. It also has a larger feature set than any of the others (though I haven't evaluated Mockiato yet). Check it out at mockall - Rust or just read the shootout for the tldr;
Congratulations @asomers, that looks seriously great!!
I just started giving it a try. One suggestion: it would be great to have somewhere that lists what #[automock] can handle and what it can't. I have a trait I was trying to mock that #[automock] choked on, but I can't seem to find docs or examples for how to use the mock! macro either.
@jasongrlicky it looks like docs.rs failed to build the docs for mockall_derive, which contain part of what you want to know. I'll see if I can fix that. I can also make a list of the other stuff that #[automock] can't handle and add it to #[automock]'s docs; I think that's a good suggestion. If you're having help, feel free to post an issue on Mockall's Github page.