[erlang-questions] Why use test generators?

Richard Carlsson richardc@REDACTED
Fri Mar 27 08:15:35 CET 2009


ryeguy wrote:
> As the title says, what situation would you be in when you would use
> test generators? The example the docs give is this:
> 
>    fib_test_() ->
>        [?_assert(fib(0) == 1),
>         ?_assert(fib(1) == 1),
>         ?_assert(fib(2) == 2),
>         ?_assert(fib(3) == 3),
>         ?_assert(fib(4) == 5),
>         ?_assert(fib(5) == 8),
>         ?_assertException(error, function_clause, fib(-1)),
>         ?_assert(fib(31) == 2178309)
>        ].
> 
> Why would you use a list of tests instead of just singlely evaluating
> each one on its own linein the fib_test() method?

Sure, you can do that. The difference would mainly be that eunit
would report it as a single test that either succeeded entirely
or failed at some particular line (and the asserts following the
failed one would not be executed). The generator version will be
reported as 8 individual tests, and even if one or more of them
fails, all tests will be executed.

    /Richard




More information about the erlang-questions mailing list