PackageTrack
Sign in Get early access

mockall

A powerful mock object library for Rust.

0.15.0 160M downloads/mo #589 most downloaded on crates.io asomers/mockall

What this package is like to depend on

Last release 1 months ago

28 Jun 2026

Ships fairly regularly

a new release about every 5 months

Nearly every release is documented

notes for 32 of 33 stable releases

Nothing withdrawn

no release was ever pulled

7 years old

34 releases · first in 2019

2 releases in the last 12 months

see the full history below

Release timeline

34 releases · Jul 2019 to Jun 2026
2020 2021 2022 2023 2024 2025 2026
Release Pre-release

Releases

latest 34
  1. 0.15.0 28 Jun 2026
    Release notes

    chore: Release mockall version 0.15.0

    Open source →
    Release notes

    Added

    • Compatibility with the #[auto_impl] macro. (#686)
    Open source →
  2. 0.14.0 22 Nov 2025
    Release notes

    chore: Release mockall version 0.14.0

    Open source →
    Release notes

    Added

    • Allow mocking structs and traits with const generics. (#649)

    • Compatibility with the #[trait_variant::make] macro. (#640)

    • Allow Expectations with a non-exact call count to be used in Sequences. (#660)

    Changed

    • The MSRV is now Rust 1.77.0. (#650)

    Fixed

    • No longer poison a static mock method's internal Mutex when panicing, even when using a stable Rust compiler. Also, no longer poison it even if there is no Context object. For example, if the user never set an Expectation at all. (#650)

    • Suppress single-use-lifetimes lints in the generated code, for cases where the orginal code wouldn't have triggered the warning. (#627)

    • Fix mocking foreign functions with a variadic argument and no pattern, for example fn foo(...) as opposed to fn bar(x: ...). That worked in prior versions of Mockall only until Rust 1.93.0, which made such arguments illegal for Rust functions. (#673)

    • Fully qualify Send and Sync traits in generated code, allowing structs named Send or Sync to be in scope without conflicts. (#672)

    Open source →
  3. 0.13.1 17 Nov 2024
    Release notes

    chore: Release mockall version 0.13.1

    Open source →
    Release notes

    Fixed

    • Suppress warnings about the #[expect] lint, new in Rust 1.81.0, in generated code. (#619)

    • Suppress the #[clippy::ref_option] warning, new in Rust 1.83.0, in generated code. (#618)

    • When mocking functions with a closure argument, but not using #[concretize], include any additional trait bounds in the trait object argument passed to .with and .returning. (#606)

    • Fixed naming conflict when mocking multiple traits with same name but from different modules. (#601)

    Open source →
  4. 0.13.0 21 Jul 2024
    Release notes

    Added

    • Add the ability to use #[concretize] with methods that have an FnMut argument. (#595)

    • Add the ability to mock methods that use #[auto_enum], from the auto_enums crate. But only for methods that use RPIT; Mockall can't yet handle syntax like -> Result<(), impl T> (#590)

    • Add the ability to mock methods that use #[inline] or #[cold], and methods or traits that use #[must_use]. (#555)

    Changed

    • Raised MSRV to 1.71.0 due to the C-unwind ABI. (#585)

    • No longer poison a Context object's internal Mutex when panicing. This requires the "nightly" feature. (#527)

    Fixed

    • Fixed panicing within mocked extern "C" functions, for example due to unsatisfied expectations, with Rust 1.81.0 or newer. (#585)
    Open source →
  5. 0.12.1 21 Dec 2023
    Release notes

    chore: Release mockall version 0.12.1

    Open source →
    Release notes

    Fixed

    • Fixed using #[mockall::concretize] on functions whose generic types contain trait bounds, yet are still object safe. (#531)

    • Fixed mocking methods that use raw identifiers for their names. This was a regression in 0.12.0. (#534)

    Open source →
  6. 0.12.0 10 Dec 2023
    Release notes

    chore: Release mockall version 0.12.0

    Open source →
    Release notes

    Added

    • Added #[mockall::concretize], which can be used to mock some generic methods that have non-'static generic parameters. It works by turning the generic arguments into trait objects for the expectation. (#408)

    • When mocking functions with a non-default ABI (Like extern "C"), the mock function will now use the same ABI as the original. Name mangling will also be disabled, so the mock function will be callable from external code. For example, from C functions. (#504)

    Changed

    • Raised predicates, which is reexported, to 3.0.0. This may affect backwards compatibility for users who make use of predicates's "color" feature. (#467)

    • Raised MSRV to 1.64.0 because predicates-core and predicates-tree did. (#430) (#467)

    • Better "No matching expectation found" messages on stable. (#425)

    Fixed

    • Fixed mocking non-private inherent methods that have attributes with syn version 2.0.9 and later. (#486)

    • Suppress clippy::too_many_arguments warnings in the generated code. This is most useful when mocking static functions with exactly 7 arguments. (#487)

    • Fixed unused_attributes warnings in the generated code when mocking FFI functions that use #[link_name]. (#503)

    • Fix a panic during Drop for static methods. One way to trigger it is by calling the method more times than is allowed by a .times() constraint. Another way would be to explicitly panic during the .returning method. (#516)

    Removed

    • Removed syntax deprecated since 0.9.0: using #[automock] directly on an extern "C" block, and using trait Foo {} syntax inside of mock!. (#476)

    • Removed default features from predicates dependency. Reexports no longer include difflib, normalize-line-endings, regex and float-cmp features. (#517)

    Open source →
  7. 0.11.4 26 Mar 2023
    Release notes

    (cargo-release) mockall version 0.11.4

    Open source →
    Release notes

    Fixed

    • Static methods' expectations will now be cleared during a panic. (#443)

    • The checkpoint method now works correctly even after a panic due to too many method calls. (#472)

    • Methods with unknown size type bounds can now be mocked. (#421)

    Open source →
  8. 0.11.3 18 Oct 2022
    Release notes

    (cargo-release) mockall version 0.11.3

    Open source →
    Release notes

    Fixed

    • Methods with a where Self: ... clause will now be mocked like concrete methods, not generic ones. Among other effects, this prevents "unused method expect" warnings from the latest nightly compiler. (#415)
    Open source →
  9. 0.11.2 24 Jul 2022
    Release notes

    (cargo-release) mockall version 0.11.2

    Open source →
    Release notes

    Fixed

    • Suppress "dead code" warnings when automocking a struct's private method. It might be used only by other public methods in the same struct. (#397)

    • Fixed using Mockall when a function named Ok is in scope. The anyhow crate, for example, creates a function by this name. (#389)

    Open source →
  10. 0.11.1 15 May 2022
    Release notes

    Fixed

    • Fixed mocking methods that use Self in their arguments, but not as the receiver. For example, PartialEq::eq has a signature like fn eq(&self, other: &Self) -> bool (#373)
    • Fixed mocking methods that return a reference to a dyn T trait object, when that trait is not already implemented for Box<dyn T>. (#380)
    Open source →
  11. 0.11.0 11 Dec 2021
    Release notes

    Added

    • mock! and #[automock] now support unsafe traits. (#313)

    Changed

    Fixed

    • Fixed nondeterministic code generation in methods with multiple lifetime parameters. (#333)
    Open source →
  12. 0.10.2 12 Jul 2021
    Release notes

    Fixed

    • Fix mocking specializing methods of non-generic structs, a regression in v0.10.0. (#309)

    • Fix mocking generic methods of generic structs returning nonstatic, a regression in v0.10.0. (#312)

    Open source →
  13. 0.10.1 02 Jul 2021
    Release notes

    Fixed

    • Fix mocking trait methods whose return values have lifetime parameters, a regression in v0.10.0. (#304)
    Open source →
  14. 0.10.0 27 Jun 2021
    Release notes

    Added

    • mock! will now allow both methods and trait impls to be gated with #[cfg()]] attributes. The attributes will be forwarded to all generated code. This allows for example only mocking certain traits on certain OSes. (#297)

    • automock will now automatically generate Debug implementations for traits and structs. mock! will to, if you put #[derive(Debug)] above the struct's name. (#289)

    • Added support for specific impls. A specific impl is an implementation of a trait on a generic struct with specified generic parameters. For example, impl Foo for Bar<i32> as opposed to impl<T> Foo for Bar<T>. Mockall does not yet support generic methods in such traits. (#274)

    Changed

    • Mockall is pickier now about how you mock a trait on a generic struct. Previously you could usually omit the generics. Now, they're required. i.e.,
      mock!{
          MyStruct<T: Bounds> {...}
          impl Foo for MyStruct {...}
      }
      
      should now be written as
      mock!{
          MyStruct<T: Bounds> {...}
          impl<T: Bounds> Foo for MyStruct<T> {...}
      }
      
      (#274)

    Fixed

    • Fixed setting simultaneous expectations with different generic types on generic methods whose generic parameters appear in neither the arguments nor the return type. (#272)
    Open source →
  15. 0.9.1 13 Feb 2021
    Release notes

    Added

    • When a test fails because of a method sequence violation, the error message will now show the method's arguments. This requires the nightly feature, and requires that the arguments implement Debug. (#247)

    • When a test fails because a mock object receives an unexpected call, the error message will now show the method's arguments. This requires the nightly feature, and requires that the arguments implement Debug. (#246)

    Changed

    Fixed

    • Fixed Clippy warnings in generated code with Rustc 1.52.0. (#255)

    • Fixed using #[automock] with #[tracing::instrument]. The mock function won't be instrumented, but at least it will compile. (#256)

    Removed

    Open source →
  16. 0.9.0 22 Dec 2020
    Release notes

    Added

    • Added the ability to mock methods returning impl Future or impl Stream. Unlike other traits, these two aren't very useful in a Box. Instead, Mockall will now change the Expectation's return type to Pin<Box<_>>. (#229)

    • Added the ability to mock methods returning references to trait objects. (#213)

    • mock! supports a new syntax: "impl Trait for". It has two benefits:

      • It can implement a generic trait for specific generic type(s).
      • It allows mocking a non-local trait. The syntax looks like this:
        mock! {
            Bar {}
            impl Foo<i32> for Bar {
                fn foo(&self, x: i32) -> i32;
            }
        }
      

      (#205)

    • #[automock] now works on modules even without the nightly feature, and no longer requires #[feature(proc_macro_hygiene)]. (#198)

    Changed

    • mock! now requires visibility specifiers for inherent methods. (#207)

    • Changed the syntax for mocking foreign functions. Instead of using #[automock] directly on the extern block, you must wrap the extern block in a module, and #[automock] that module. The old method is deprecated. (#201)

    Fixed

    • Fixed mocking methods that return Self inside of a trait object with multiple bounds. For example: -> impl Future<Output=Self> + Send (3400916)

    • Fixed setting multiple expectations on generic methods whose only generic type is the return. (#238)

    • Fixed mocking generic structs with generic methods whose only generic types are lifetimes. This is useful for mocking generic structs that implement traits like Future and Stream. (#225) (#226) (#228)

    Removed

    • Removed times_any and times_range methods from Expectations. They've been deprecated since 0.3.0. (#197)
    Open source →
  17. 0.8.3 22 Oct 2020
    Release notes

    Added

    Changed

    Fixed

    • Suppressed default_trait_access pedantic Clippy lint in generated code (#222)
    Open source →
  18. 0.8.2 13 Oct 2020
    Release notes

    Added

    Changed

    Fixed

    • Fixed Clippy warnings for mocked methods with Vec or String arguments. (#195)
    Open source →
  19. 0.8.1 08 Sep 2020
    Release notes

    Added

    Changed

    Fixed

    • Fixed using <X as Y>::Z syntax in a where clause or a return type. (#208)

    Removed

    Open source →
  20. 0.8.0 29 Aug 2020
    Release notes

    Added

    • Added support for mocking structs and traits with associated constants. (#187)

    • Methods returning slices can now be mocked. Their expectations take Vecs. (#185)

    • Compatibility with the #[async_trait] macro. (#183)

    • Better support for non-Send types:

      • Added return_const_st for returning non-Send constants, similar to returning_st.
      • Added return_once_st for static methods. It was already available for non-static methods. (#178)
    • Support mocking methods with arbitrary receivers like self: Box<Self> (#176)

    • Support mocking methods with trait object arguments that use implicit lifetimes. (#174)

    Changed

    • Raised the minimum supported Rust version (MSRV) to 1.42.0. (#175)

    • Mocked modules now have the same visibility as the original module. (#169)

    Fixed

    • Fixed mocking modules including functions that use "impl Trait" or mutable arguments. (#169)

    • Fixed mocking methods whose generic types include super::. (#167)

    • Fixed mocking generic methods with where clauses returning references. (#166)

    • Fixed mocking generic methods returning mutable references. (#165)

    • Suppressed incomplete_features warnings in the latest nightly. (#161)

    Removed

    Open source →
  21. 0.7.2 29 Jul 2020
    Release notes

    Added

    Changed

    Fixed

    • Fixed handling function attributes. They already worked on methods, but not foreign functions or module functions. (#129)

    • Propagate doc comments for module functions to the generated mock functions. (#132)

    • Fix the formatting of generated doc comments for context methods (#132)

    • Fixed some visibility issues in the generated mocks for modules and extern functions. (#133)

    • Fixed mocking methods with complicated types including a super:: component. (#137)

    • Mocked generic static methods can now use return_const. This capability was omitted as an oversight from PR #47. (#141)

    • Suppressed unused unit warnings from Clippy in the latest nightly. (#148)

    Removed

    Open source →
  22. 0.7.1 03 May 2020
    Release notes

    Fixed

    • Fixed unused must_use warnings in consumers' crates on the latest nightly (#124) (#125)
    Open source →
  23. 0.7.0 29 Mar 2020
    Release notes

    Added

    • mock! now allows doc comments in any position (#102)

    • Added the ability to match non-Send arguments with withf_st (#93)

    • Added the ability to mock non-'static structs (but not their constructor methods) (#114)

    Changed

    Fixed

    • Fixed the docs for mockall_examples (#103)

    • Fixed the build with nightly compilers 2020-03-11 and later. This also raises the MSRV to 1.36.0. (#108)

    • The proc macros will now build successfully in crates that set #![deny(missing_docs)] (#107)

    • Fixed mocking methods with an explicit receiver lifetime like &'a self (#112)

    Removed

    Open source →
  24. 0.6.0 06 Dec 2019
    Release notes

    Added

    • Added the ability to mock generic methods whose return values' lifetimes are chosen by the caller. Especially useful with std::future::Future (#86)

    Changed

    Fixed

    • Fixed using prediate::always and prediate::never with ?Sized types (#80)

    • Fixed mocking methods when a custom Result type is in-scope. (#74)

    Removed

    Open source →
  25. 0.5.2 02 Nov 2019
    Release notes

    Added

    Changed

    • Mock objects' checkpoint methods will no longer check static expectations. This behavior is more useful where static and regular methods are both used in the same test. The old behavior was a relic from release 0.3.0 and before, when static methods did not yet have Context objects of their own. (#64)

    Fixed

    • Fixed hygiene violations in some of mockall_derive's warnings. (#63)

    Removed

    Open source →
  26. 0.5.1 28 Sep 2019
    Release notes

    Added

    Changed

    Fixed

    • Fixed using super:: in the signature of a bare function (#54)

    • Fixed automocking modules that contain use statements importing types that are used in function signatures. (#53)

    Removed

    Open source →
  27. 0.5.0 06 Sep 2019
    Release notes

    Added

    • Many generic methods with lifetime parameters can now be mocked. The condition is that they may not also have generic type parameters, and their return values must be 'static. (#48)

    • Reexport more traits from the predicates crate (09746e9)

    Changed

    Fixed

    • return_const now works for static methods with no preceding with or withf. (#47)

    Removed

    Open source →
  28. 0.4.0 29 Aug 2019
    Release notes

    Added

    • Warnings for misued expectations and context objects (#37)

    • Methods with closure arguments and where clauses can now be mocked. (#35)

    • Mocked static methods and free functions now use a Context object to manage their expectations. The context object will validate call counts when it drops, and clean up any leftover expectations. This makes it practical to use mocked free functions from multiple test cases. The user still will most likely need to provide his own synchronization to prevent such test cases from running concurrently. (#34)

    Changed

    • Better panic messages when an expectation fails its expected call count. (#33)

    Fixed

    • Fixed mocking methods that return 'static deref types, like &'static str (#39)

    • Methods returning non-'static references (mutable or otherwise) will now return a default value if no return value is set, if the output type implements Default and the nightly feature is enabled. This more closely matches existing behavior for methods returning non-reference types. (#32)

    Removed

    Open source →
  29. 0.3.0 10 Aug 2019
    Release notes

    Added

    • Methods with closure arguments can now be mocked. Technically they always could be, but until now it wasn't possible to call the closure argument from withf or returning. No special tricks are required by the user. Similarly, methods with bare fn arguments can be mocked, too. (#15)

    Changed

    • It is no longer necessary for consuming crates to explicitly depend on fragile, downcast, or predicates-tree. Mockall now reexports them. (#29)

    • The MSRV is now Rust 1.35.0 (#15)

    • The times method now accepts ranges as arguments. types_any and times_range are deprecated. (#14)

    Fixed

    • Fixed mocking methods with arguments or return values that use Self as an associated type of some other trait. (#28)

    • Fixed mocking structs and traits with more than one static method. (#22)

    • Methods of generic structs and traits that reference Self (such as constructors or comparators) can now be mocked without any hacks. (#21) (#25)

    • Specializing methods of generic structs (and traits) can now be mocked without the hack of duplicating the struct's (or trait's) generic parameters. (#20)

    • Static methods of generic structs (and traits) can now be mocked without the hack of duplicating the struct's (or trait's) generic parameters. (#19)

    Removed

    Open source →
  30. 0.2.1 03 Aug 2019
    Release notes

    Fixed

    • Fixed some hygiene problems introduced in 0.2.0 (db25804)
    Open source →
  31. 0.2.0 03 Aug 2019
    Release notes

    Added

    • Support mocking generic specializing methods. (#13)

    • Correctly handle where clauses on mocked methods. (#13)

    • Allow mocking generic constructor methods (#11)

    • Allow mocking methods that use super somewhere in their signatures. (#8)

    Changed

    Fixed

    • Fixed #[automock] for new methods with arguments. (#3)

    • Fixed the never method, which never actually worked. (#10)

    • Fixed mocking generic traits or structs with generic methods (6126359)

    • Fixed an issue with using associated types in generic parameter bounds (116e5a2)

    • Fixed mocking methods with mutable arguments (8058701)

    Removed

    • Removed expectation!, used to manually mock methods in rare circumstances. Now mock! and #[automock] are the only way to use Mockall. (#12)
    Open source →
  32. 0.1.1 03 Jul 2019
    Release notes

    Added

    Changed

    Fixed

    • Fixed some issues in the API docs. No functional change. (ba88fd1)

    Removed

    Open source →
  33. 0.1.0 03 Jul 2019

    Nothing published for this version

  34. 0.1.0-pre 03 Jul 2019 pre-release

    Nothing published for this version

Every package, every release, already written down.

The archive is open and free. Watching your own project is what we are building next.

Browse the archive