[erlang-questions] Eunit fixtures - can someone show an example?

Richard Carlsson richardc@REDACTED
Sat Mar 28 22:41:18 CET 2009


ryeguy wrote:
> Ok, what am I doing wrong here? How do I pass what the setup function
> returned on to the tests?
> 
> ...
> 
> 			?_test(fun register_normal/1)

There's your problem. This is like writing ?_test(42) or
?_test("hello"), i.e., it simply tests that it can create
the fun-value (and if it goes through the compiler, then
it should).

You can either write like this:

register_test_() ->
	{setup, fun register_setup/0, fun register_teardown/1,
		fun(User) -> [
			?_test(register_normal(User))
		] end}.

or, using the special "with"-construct:

register_test_() ->
	{setup, fun register_setup/0, fun register_teardown/1,
		{with, [
			fun register_normal/1
		] end}.

(Your register_normal/1 function is what the eunit documentation calls
an "abstract test", i.e., like a normal test function but missing some
data in order to run.)

     /Richard




More information about the erlang-questions mailing list