【发布时间】:2013-08-10 17:01:13
【问题描述】:
我正在使用 meck 测试我的 gen_server mymodule。特别是,我按照here 提供的说明使用meck 模拟httpc。
这是我从测试中提取的一些代码:
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.
使用此代码,我可以运行测试,但仍有两件事我无法理解:
1) 在结果中我得到如下内容:
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
是否可以为每个测试只获取一行而不是两行?
2) 如何为每个测试添加口语描述?
【问题讨论】: