Structuring unit tests

erlang-list@REDACTED erlang-list@REDACTED
Mon Apr 18 22:53:57 CEST 2005

Gaspar Chilingarov wrote:

> Well, and how do you test functions, which are not
> exported from foo module? I'm getting a lot of utilitary
> functions,. which are used only inside of module, but i
> want to test them explictly.

I find that I don't usually need to explicitly. This is
probably because I rarely create such functions at first: I
start by writing the principal, exported function so that it
passes simple cases, then as the test becomes more robust
and the exported function more complicated, I extract parts
of it into an auxiliary function (which is implicitly tested
by the unit test for the principal function).

> another question - how do you following thing in Erlang?
> in OO world I can define some object, then inherit from
> it in unit test, and override some functions. Thus i can
> create necessary environment for tested class. How this
> can be implemented in Erlang? I also accept answers "this
> is not an erlangish way at all" :)

I write a separate function that builds up the necessary
environment, and call it explicitly at the beginning of any
test that needs that environment.

Or, more often, as I also need to tear down the environment,
I have a higher order function that sets up the environment,
executes a fun (passing it the environment), catches any
crashes, and then tears down the environment.


Dominic Williams


More information about the erlang-questions mailing list