Unit testing 使用eunit启动相关应用程序
当我运行单元测试时,我将lager作为一个依赖的应用程序启动,但由于某些原因,被测试的代码没有看到它Unit testing 使用eunit启动相关应用程序,unit-testing,erlang,eunit,Unit Testing,Erlang,Eunit,当我运行单元测试时,我将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 pi
-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.
这是日志的输出,它抱怨没有定义lager
{unde,[{lager,info,[“启动并运行”],[]}尽管在运行中输出肯定存在
以下是我如何运行它:
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.
Eshell V5.10.2(使用^G中止)
1> 17:13:31.506[信息]节点上已启动应用程序延迟nonode@nohost
==========================================================EUnit========================
模块“主测试”
未定义
17:13:31.528[错误]1个邻居的崩溃报告进程退出,原因是:调用gen_服务器中未定义的函数lager:info(“启动并运行”):init_it/6第328行
*测试过程的意外终止*
::**{unde,[{lager,info,[“启动并运行”],[]}**,
{mary_counter,init,1,[{file,“src/mary_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}]}
=======================================================
失败:0。跳过:0。传递:0。
一个或多个测试被取消。
已经在google和stack overflow上花费了3-4个小时,但似乎没有任何效果
一种选择是将此调用隐藏在?INFO(Mgs)宏后面,但不喜欢这个想法
任何帮助都将不胜感激。因此看起来
src/parse\u counter.erl
文件不是使用{parse\u transform,lager\u transform}
选项编译的
函数lager:info(“message!”)
,实际上并不存在,解析转换将lager:info(“message!”)
转换为以下函数:lager:dispatch\u log(info,Metadata,“message!”,[],Size)
尝试使用{parse\u transform,lager\u transform}
选项重新编译模块
Lager演示了如何执行此操作:.因此看起来
src/滥用计数器.erl
文件不是使用{parse\u transform,Lager\u transform}
选项编译的
函数lager:info(“message!”)
,实际上并不存在,解析转换将lager:info(“message!”)
转换为以下函数:lager:dispatch\u log(info,Metadata,“message!”,[],Size)
尝试使用{parse\u transform,lager\u transform}
选项重新编译模块
Lager演示了如何做到这一点: