Unimock - a new kind of trait mocker

Unimock (docs) is a trait mocking library. Its defining feature is that all generated mock implementations are implemented for the same type (Unimock). This design allows using a mock object where the type of the generic value is constrained by several trait bounds at the same time (e.g. T: Foo + Bar).

Other features:

  • Declarative verification of calls up front (executed at Drop-time)
  • Argument matching through pattern matching or Eq
  • Partial mocking (though this needs to be manually integrated with some "canonical implementation")
  • Versatile support for different types of return values, including borrowed values
  • Largely implemented via generics, the macro expansions keep the size of generated code to an absolute minimum
  • Safe Rust™
4 Likes

This looks pretty good :slight_smile: my only feedback at this point would be to maybe show some examples with #[cfg_attr(test, unimock(api=FooMock)], this way the unimock code is only generated with the tests.

Hmm, yes, the documentation could include/mention that just to demonstrate the feature. I've focused on doctest-verifiable code examples.

edit: I'll make a note of this and most likely include this in the doc for the next minor version.