I am using meck to test my gen_server mymodule
. In particular I use meck to mock httpc
following the instructions provided here.
Here is some code I extracted from my test:
do_some_tests_() ->
{foreach,
fun start/0,
fun stop/1,
[fun do_some_stuff/1,
fun do_some_other_stuff/1
]}.
start() ->
{ok, _} = mymodule:start_link(),
meck:new(httpc),
_Pid = self().
stop(_) ->
meck:unload(httpc),
mymodule:stop().
do_some_stuff(Pid) ->
%% here i use meck
meck:expect(httpc, request,
fun(post, {_URL, _Header, ContentType, Body}, [], []) ->
Reply = "Data to send back"
Pid ! {ok, {{"", 200, ""}, [], Reply}}
end),
%% here i do the post request
mymodule:myfunction(Body),
receive
Any ->
[
?_assertMatch({ok, {{_, 200, _}, [], _}}, Any),
?_assert(meck:validate(httpc))
]
end.
With this code I am able to get the tests running but there are still two things I can't understand:
1) In the results I get something like:
mymodule_test:43: do_some_stuff...ok
mymodule_test:43: do_some_stuff...ok
mymodule_test:53: do_some_other_stuff...ok
mymodule_test:53: do_some_other_stuff...ok
Is it possible to get only one line for each test instead of two?
2) How can I add a speaking description for each test?
The function
do_some_stuff(Pid)
generates two tests, so it's pretty normal both are checked and displayed.You can however add a name/description to each generator & test:
This should display something in the likes of:
In EUnit parlance, these are know as "titles":
http://www.erlang.org/doc/apps/eunit/chapter.html#id61107