[erlang-questions] Mocking processes for testing

June Kim <>
Sun Aug 12 06:37:37 CEST 2007

Hi, Michael, Glad to see you here.

I've tested processes behaviors in Erlang with a lot of ease. It's
really easy. All you have to do is pass around pid instead of global
reference, just like DIP in OOP.

Suppose process A should wait for msg1 from process C and then once it
receives, it should emit msg2 to process B.

You want to test the behavior of process A.

You first spawn a mock process MockB which just waits for msg2 and
then it sends you "test passed" back(I mean back to the testing
process). Now, you spawn process A with the pid of MockB. You also
need to spawn a stub process MockC(along with the pid of process A)
which just sends msg1 to process A.

You can easily build a mock framework, discovering and refactoring the
repeating patterns.

If you want more detail, I'll work on a concrete example code.


2007/8/12, Michael Feathers <>:
> Hi.  New to the language and just reading Joe Armstrong's book.
> I was just wondering.. is there any facility in the language to allow
> you to create mock processes, so that outgoing process calls can be
> intercepted under test?
> Michael
> _______________________________________________
> erlang-questions mailing list
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list