[ANN] gen_server_mock: a simple gen_server mocking library

Nate Murray nate@REDACTED
Tue Aug 11 21:00:19 CEST 2009

Hey guys, I was inspired by [this
write a simple gen_server mocking library. [Github

It is by no means complete. Currently it only supports specific
ordered messages (although my hope is to eventually add at-least-N,
at-most-N etc.).
Here's a code example:

         {ok, Mock} = gen_server_mock:new(),

         gen_server_mock:expect_call(Mock, fun(one,  _From, _State)
        -> ok end),
         gen_server_mock:expect_call(Mock, fun(two,  _From,  State)
        -> {ok, State} end),
         gen_server_mock:expect_call(Mock, fun(three, _From,  State)
        -> {ok, good, State} end),
         gen_server_mock:expect_call(Mock, fun({echo, Response},
_From, State) -> {ok, Response, State} end),
         gen_server_mock:expect_cast(Mock, fun(fish, State) -> {ok, State} end),
         gen_server_mock:expect_info(Mock, fun(cat,  State) -> {ok, State} end),

         ok = gen_server:call(Mock, one),
         ok = gen_server:call(Mock, two),
         good = gen_server:call(Mock, three),
         tree = gen_server:call(Mock, {echo, tree}),
         ok   = gen_server:cast(Mock, fish),
         Mock ! cat,


Download it here: git clone git://github.com/jashmenn/gen_server_mock.git
Introductory blog post:

Feedback and patches welcome.

Nate Murray

More information about the erlang-questions mailing list