Fork me on GitHub

Unit test aid for Erlang


I noticed erlymock today. It’s for mocking dependencies in Erlang so that tests can be performed in isolation.

I have just studied it briefly, but im not sure this is how I would want to work with mocks in erlang unit tests. I imagine a unit-test that uses something like:

  GenServerFun =
     fun (call, {do_stuff, X}) ->
       {reply, X}
  GenServerMock = mock:gen_server(GenServerFun),
  gen_server:call(GenServerMock, {do_stuff, 1}).

This would replace the full gen_server (with the separate module and all the behavior callbacks). Preferably the mock-servers should not need internal state. But it would not be difficult to add.

Testing in the small

Something is to be said about putting most of your effort into unit tests. A unit test is least fragile. They take the smallest amount of time to develop, and real unit tests should not break if anything else than the code under test is changed.

The higher you get in testing, the more likely it is that you will break tests when you change things in intended ways.

Not to self, maybe I should implement that mocking library, I’ve got all weekend.