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

ryeguy <>
Sat Mar 28 18:39:31 CET 2009


Ok, what am I doing wrong here? How do I pass what the setup function
returned on to the tests?

%randomly generate a username and email address
register_setup() ->
	{u:random_str(10), list_to_binary([u:random_str(3), <<"@">>,
u:random_str(3), <<".com">>])}.

register_teardown({Username,_}) ->
	mnesia:dirty_delete(hd(mnesia:dirty_index_read(user, Username,
#user.username))).

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

instantiate_test(Fun) ->
	fun(Fixture) -> ?_test(Fun(Fixture)) end.

register_normal({Username, Email}) ->
	?debugMsg(asdasd),
	?_assert(ok == users:register([Username, Email, <<"abc123">>])).

My register_normal function is not even being called. Why?
On Mar 27, 3:50 pm, Hasan Veldstra <> wrote:
> Here's a basic example:
>
> simple_test_() ->
>      {setup, local,
>       fun setup/0,   %% This is called before the tests are run (to  
> set up things).
>       fun cleanup/1, %% This is called after the tests have been run  
> (to clean up).
>       fun(List) ->   %% The argument to this is the return value of  
> setup().
>               [
>                ?_assert(2*2 == 4),
>                ?_assert(not(true) == false)
>               ]
>       end}.
>
> I haven't tried to run it but it should work.
>
> --http://12monkeys.co.uk
>
> On 27 Mar 2009, at 19:23PM, ryeguy wrote:
>
> > Can someone show me an example of a test fixture with a setup and
> > teardown function? The docs are sparse in this area, and don't have
> > any examples of it. I can't figure it out.
>
> > _______________________________________________
> > erlang-questions mailing list
> > 
> >http://www.erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> ://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list