Search code examples
automated-testserlangerlang-otperlang-shelleunit

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:

debugMsg(Text) Outputs the message Text (which can be a plain string, an IO-list, or just an atom). 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? 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.


Solution

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

    edit: This is because it is a macro. You can find it under Debugging macros in the Eunit docs.