[erlang-questions] mockgyver -- yet another mocking library

Klas Johansson klas.johansson@REDACTED
Wed Nov 2 21:47:12 CET 2011

Hi all,

I'd like you to meet mockgyver -- an Erlang tool which will make it
easier to write EUnit tests that need to replace or alter (stub/mock)
the behaviour of other modules.

mockgyver aims to make that process as easy as possible with a
readable and concise syntax.

mockgyver is built around two main constructs: ?WHEN which makes it
possible to alter the behaviour of a function and another set of
macros (like ?WAS_CALLED) which check that a function was called with
a chosen set of arguments.  Let's redefine pi to 4:

       ?WHEN(math:pi() -> 4),
       4 = math:pi(),

Use pattern matching to check that a function was called with certain arguments:

       ?WAS_CALLED(lists:reverse([a, b, c])),

... or if you don't care about the arguments:


The library has been in use for a year for a bunch of Erlang
applications, except for a couple of recent additions.

A short tutorial as well as docs and many more examples[1] in markdown
format on github:



[1] https://github.com/klajo/mockgyver/blob/master/doc/mockgyver.md

More information about the erlang-questions mailing list