【问题标题】:Start dependent application with eunit使用 eunit 启动依赖应用程序
【发布时间】:2013-11-12 01:47:28
【问题描述】:

我在运行单元测试时将 lager 作为依赖应用程序启动,但由于某种原因,被测代码看不到它。

-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.

这是抱怨未定义啤酒的日志的输出 {undef,[{lager,info,["up and running"],[]} 虽然在运行中输出肯定存在。

这是我的运行方式:

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

输出失败

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.

已经在 google 和堆栈溢出上花费了 3-4 小时,但似乎没有任何效果。

一种选择是将这个调用隐藏在 ?INFO(Mgs) 宏后面,但不喜欢这个想法。

我们将不胜感激。

【问题讨论】:

    标签: unit-testing erlang eunit


    【解决方案1】:

    所以看起来src/abuse_counter.erl 文件没有使用{parse_transform, lager_transform} 选项编译。

    函数lager:info("message!"),真的不存在,parse_transform把lager:info("message!")转换成这个函数:lager:dispatch_log(info, Metadata, "message!", [], Size)

    尝试使用{parse_transform, lager_transform} 选项重新编译您的模块。

    Lager 展示了如何做到这一点:link to the Readme

    【讨论】:

      猜你喜欢
      • 2012-10-29
      • 1970-01-01
      • 1970-01-01
      • 2015-01-21
      • 2014-09-18
      • 1970-01-01
      • 2020-12-01
      • 2017-05-13
      • 2016-10-05
      相关资源
      最近更新 更多