Start dependent application with eunit

Posted by ruslander on Stack Overflow See other posts from Stack Overflow or by ruslander
Published on 2013-10-31T21:30:58Z Indexed on 2013/10/31 21:54 UTC
Read the original article Hit count: 240

Filed under:
|
|

I start lager as a dependent application when I run a unit test but for some reason the code under test does not see it.

-module(main_tests).
-include_lib("eunit/include/eunit.hrl").

main_test_() ->
{foreach,
 fun distr_setup/0,
 fun distr_cleanup/1,
 [
  fun must_retain/1
  ]}.

must_retain(_) ->
{"Should do ping pong when is fully initialized",
 fun() ->
     ?assertEqual(pong, abuse_counter:ping())
 end}.



%%------------------------------------------------------------------
distr_setup() ->
abuse_counter:start_link(),
ok.

distr_cleanup(_) ->
abuse_counter:stop(),
ok.

Here is the output of the log which is complaining that lager is not defined {undef,[{lager,info,["up and running"],[]} though in the run output is definitely there.

Here is how I run it:

erl -pa ebin/ ../../deps/*/ebin -s lager -eval 'eunit:test(main_tests,[verbose]),    init:stop().'

Fails with the output

Eshell V5.10.2  (abort with ^G)
1> 17:13:31.506 [info] Application lager started on node nonode@nohost
======================== EUnit ========================
module 'main_tests'
undefined
17:13:31.528 [error] CRASH REPORT Process <0.57.0> with 1 neighbours exited with reason: call to undefined function lager:info("up and running") in gen_server:init_it/6 line 328
*unexpected termination of test process*
::**{undef,[{lager,info,["up and running"],[]}**,
      {abuse_counter,init,1,[{file,"src/abuse_counter.erl"},{line,37}]},
      {gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]},
      {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]}

=======================================================
 Failed: 0.  Skipped: 0.  Passed: 0.
 One or more tests were cancelled.

Already spent 3-4h hours on google and stack overflow but nothing seems to work.

One option is to hide this call behind a ?INFO(Mgs) macro but do not like the idea.

Any help will be highly appreciated.

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about erlang