Moved to a similar problem. Found another way thanks to @rvirding. The solution is to write to the user's output stream (as in io:format(user, "~w", [Term]) ).
This is described in the EUunit captures standard output section of eunit docs .
My trace.hrl file is shown below:
%% If compiled with {d, TEST, true} %% This happens automatically during `rebar3 eunit` -ifdef(TEST). -define(TRACE(Template, Args), io:format(user, "TRACE ~p:~p ~p~n", [?MODULE, ?LINE, lists:flatten(Args)])). -else. -define(TRACE(_T, _A), void). -endif.
An example of the source file:
-module(foo). -export([ api/1 ]). -include("trace.hrl"). api(Arg) -> ?TRACE("Called with Arg ~p~n", [Arg]), ok.
I prefer this method ?debugFmt , since the latter introduces special EUnit code in your source code (and not a test).
source share