[erlang-questions] EUnit fixture: return of Setup

Ludovic Coquelle lcoquelle@REDACTED
Sat Nov 3 16:21:51 CET 2007


I'm discovering that EUnit is really powerful.
I'll be more careful next time with test generation/run function.
Thanks.

On 11/3/07, Richard Carlsson <richardc@REDACTED> wrote:
>
> Ludovic Coquelle wrote:
> > I have some problem with the EUnit fixture {setup, Setup, Clearup,
> > Instanciator}.
> >
> > From the doc, I understand that the Instanciator should get the value
> > return by the Setup.
> > But in the following case, the test fail because assertion is "undefined
> > == foo".
> > Am I missing something?
> >
> > simple_init() ->
> >     foo.
> > simple_close(R) ->
> >     R.
> > simple_do(R) ->
> >     ?assert(R == foo).
> > simple_test_() ->
> >     {
> >         setup,
> >         fun simple_init/0,
> >         fun simple_close/1,
> >         fun simple_do/1
> >     }.
>
> It does get the value from Setup during the test phase, but there is a
> previous phase which tries to enumerate the tests, and that will pass
> a dummy value ('undefined') to avoid actually running the setup.
>
> Note that the name of your 'simple_do/1' function is misleading: since
> it takes a parameter, EUnit assumes that it is (as you said) an
> instantiator which should get the value from simple_init/0, and should
> *return a test descriptor*, not try to run a test.
>
> If you try the following, you will see what is happening:
>
> simple_do(R) ->
>   eunit:debug(R),
>   ?_assert(R == foo).  % note the underscore: return test, don't run it
>
> (simple_do/1 is run twice - the first time with R='undefined').
>
> Although EUnit is powerful and compact to write, I know that it
> can be hard to keep in mind whether you should currently be writing
> test-running code of test-generating code.
>
>     /Richard
>
>
> --
> "Having users is like optimization: the wise course is to delay it."
>    -- Paul Graham
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071103/510f1b64/attachment.htm>


More information about the erlang-questions mailing list