[erlang-questions] Mocking in Erlang

Dominic Williams <>
Mon May 26 13:41:11 CEST 2008


Hi Jeremy,

> While browsing the erlang-questions list archives I found mention that
> someone had written a Mocking Module for erlang that would mock processes.
> I'm wondering if that ever got published anywhere or if there are other
> mocking frameworks for erlang that have been used. I love TestFirst
> development but it would be a lot easier if I could mock outside sources
> when I write my tests.

Because the "protocol" (or alphabet) of an Erlang process is not
formalised (there is no interface definition), it is completely trivial to
to implement a mock of a process (with just enough messages for the
context of the test), so I write mocks all the time without needing a
framework.

Sometimes, I pass the test's self() directly and send/receive from the
test function. Sometimes, the test is a bit cleaner if I spawn a fun() ->
... end that is hard-coded to receive and/or send the exact messages I
need to make my test work.

It's so straightforward that I can't imagine a framework would do any good.

Regards,

Dominic Williams
http://dominicwilliams.net

----




More information about the erlang-questions mailing list