[erlang-questions] meck

Motiejus Jakštys <>
Mon Jul 23 10:07:59 CEST 2012


On Mon, Jul 23, 2012 at 4:15 AM, Roberto Ostinelli <> wrote:
> dear all,
>
> for instance:
>
> %%%%%%%%%%%%%%%%%%%%
>
> -module(example).
> -compile(export_all).
>
> get_config() ->
> mocked:myfun("test.config").
>
> -ifdef(TEST).
> -include_lib("eunit/include/eunit.hrl").
>
> get_config_test_() ->
> meck:new(mocked),
> meck:expect(mocked, myfun, fun(Filename) -> ok end),
> ?_assertEqual(ok, get_config()),
> ?_assert(meck:validate(mocked)).
> -endif.

Hi,
you are mixing eunit generators with simple test cases. Did you mean this?

get_config_test() ->
  meck:new(mocked),
  meck:expect(mocked, myfun, fun(Filename) -> ok end),
  ?assertEqual(ok, get_config()),
  ?assert(meck:called(mocked, myfun, ["test.config"])),
  meck:unload(mocked).

Normally, you should split meck:new and meck:unload to separate
setup/cleanup functions. Because if a test fails and the module is not
cleaned, it might unexpectedly do ill for your other test cases.

-- 
Motiejus Jakštys



More information about the erlang-questions mailing list