Structuring unit tests
Kostis Sagonas
kostis@REDACTED
Fri Apr 15 14:28:59 CEST 2005
Thomas Lindgren gave the following advice:
>
> --- Joel Reymont <joelr1@REDACTED> wrote:
> > exporting all the tested functions or placing a
> > -compile([export_all]) at the top of the module to be tested.
>
> You can also do that with a command line option:
>
> % erlc +export_all mymod.erl
>
> That means you can make it a flag in the makefile,
> which often is useful.
Please do not follow these paths, and please do not give such "advice".
Do the following instead: If you have a module m that exports
functions f1, ..., fn and contains test functions t1, ..., tm, which
are internal (i.e., module-local) and return 'ok' when passing the
test, export a *single* function test/0 which looks as follows:
test() ->
ok = t1(...),
ok = t2(...),
...
ok = tm(...).
If you absolutely positively need to test t1, ..., tm individually,
then export a function test/1 which looks as:
test(t1) ->
ok = t1(...);
test(t2) ->
ok = t2(...);
...
test(tm) ->
ok = tm(...).
There is very little reason to use 'export_all' for this task.
Best,
Kostis
More information about the erlang-questions
mailing list