简体   繁体   English

如何在 eunit 中使用 debugMsg 以及如何在 eunit 测试中打印一些东西,尽管测试超时

[英]How to use debugMsg in eunit and how to print something within the eunit testing although the test times out

I try to get the following to work as described in the erlang eunit documentation :我尝试让以下内容按照 erlang eunit 文档中的描述工作:

debugMsg(Text) Outputs the message Text (which can be a plain string, an IO-list, or just an atom). debugMsg(Text) 输出消息文本(可以是纯字符串、IO 列表或只是一个原子)。 The result is always ok.结果总是好的。

I do however get the following when using it in my code:但是,在我的代码中使用它时,我确实得到了以下信息:

-module(test_rps).
-export([test_all/0]).

%% Maybe you want to use eunit
-include_lib("eunit/include/eunit.hrl").

test_all() ->
    eunit:test(
      [   
       test_drain_player_receive()       
      ], [verbose]).


test_drain_player_receive() ->
    {"Test players receival of server_stopping w. drain through RPS module",
    fun() -> io:format("Testing ~p",[]), debugMsg("SomeText")      
    end
    }.



function debugMsg/1 undefined
%  340|         debugMsg(Text),
%     |         ^

Do I use it in a wrong way?我是否以错误的方式使用它? Is it supposed to go in the console instead or something?它应该在控制台中改为 go 还是什么? The same seems to be the case with the other functions described in the section of the documentation I referred to above.我在上面提到的文档部分中描述的其他功能似乎也是如此。

Secondly, what is a good way to print ( io:format(...) ) or the like within an eunit test that times out, such that the printing can be used for debugging and point to specific code lines etc.其次,在超时的 eunit 测试中打印( io:format(...) )等的好方法是什么,这样打印可用于调试并指向特定的代码行等。

Ok I figured it out.好的,我想通了。 The documentation just doesn't specify that you should add ?该文档只是没有指定您应该添加? in front of the function like any other eunit function. That is why it didn't work before I wrote ?debugMsg(Text)在 function 前面,就像任何其他 eunit function 一样。这就是为什么在我写?debugMsg(Text)之前它不起作用的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM