[erlang-questions] Eunit question...

11 views
Skip to first unread message

Bryan Hughes

unread,
Nov 6, 2011, 3:58:30 PM11/6/11
to Erlang
Hi Everyone,

Hoping someone might be able to help me understand how to set up a unit test with EUnit which needs both timeout and fixture setup/cleanup.  I find the documentation a bit challenging on this particular aspec.

For example, according to the documentation for using the fixture pattern:

{setup, Setup, Tests | Instantiator}

{setup, Setup, Cleanup, Tests | Instantiator}

{setup, Where, Setup, Tests | Instantiator}

{setup, Where, Setup, Cleanup, Tests | Instantiator}



So my normal tests look like:

my_test_() ->
    {setup,
     fun setup/0,
     fun cleanup/1,
     ?_test(begin
                ...
            end)}.

For using adjusting the timeout, the documentation describes this pattern:

{timeout, Time::number(), Tests}

I have not been able to figure out how to craft my test.  Unfortunately my variations just fail, or just quietly end without running any of the remaining tests for the module.


Thanks!!!

Cheers,
Bryan

Gianfranco Alongi

unread,
Nov 6, 2011, 4:12:59 PM11/6/11
to Bryan Hughes, Erlang
You put the timeout in the Tests.

-module(demo_tests).
-include_lib("eunit/include/eunit.hrl").
timeout_setup_test_() ->
{setup,
fun() -> ok end,
fun(_) -> ok end,
{timeout,20,
fun() -> ok = demo:a() end}}.


-module(demo_tests).
-include_lib("eunit/include/eunit.hrl").
timeout_setup_test_() ->
{setup,
fun() -> ok end,
fun(_) -> ok end,
{timeout,20,
fun() -> ok = demo:a() end}}.


erlc *.erl
erl
eunit:test(demo).

> _______________________________________________
> erlang-questions mailing list
> erlang-q...@erlang.org
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Gianfranco Alongi

unread,
Nov 6, 2011, 4:16:49 PM11/6/11
to Bryan Hughes, Erlang
Sorry, seems like I got double paste in there, second paste should
have been demo.erl

-module(demo).
-export([a/0]).
a() ->
timer:sleep(10000),
ok.

Bryan Hughes

unread,
Nov 6, 2011, 4:32:51 PM11/6/11
to Gianfranco Alongi, Erlang
This is perfect! Thank you. I was trying to get the setup fixture
pattern inside the timeout tuple, which just quietly ended tests.

It's really great to have such a helpful and active community - very
much appreciated!

Regards,
Bryan

Reply all
Reply to author
Forward
0 new messages