Timeout control in EUnit

Koushik Narayanan <>
Thu Jun 4 17:19:37 CEST 2009


Hi,

How do we specify timeout for tests in eunit, 
when the test module has more than one generator?

This is what I tried:

%% t1.erl
-module(t1).

-include_lib("/usr/lib/erlang/lib/eunit-2.1/include/eunit.hrl").

slow_test_() ->
        [fun() ->
                timer:sleep(10000)
         end
        ].

fast_test_() ->
        [fun() ->
                ok
         end
        ].


%% t2.erl
-module(t2).

-include_lib("/usr/lib/erlang/lib/eunit-2.1/include/eunit.hrl").

slow_test_() ->
        [fun() ->
                timer:sleep(10000)
         end
        ].

Then on the shell:

1> c(t1).
{ok,t1}
2> c(t2).
{ok,t2}
3> eunit:test({timeout,60,t1}).
t1: slow_test_...*timed out*
undefined
=======================================================
  Failed: 0.  Skipped: 0.  Passed: 0.
One or more tests were cancelled.
error
4> eunit:test({timeout,60,t2}).
  Test passed.
ok


Thanks,

Koushik Narayanan


More information about the erlang-questions mailing list