Showing full expected and value information when ?_assertEqual fails

谁都会走 提交于 2019-12-05 11:28:02

The best I can think of for actually showing the value in the console is something like this:

Actual =:= Expected orelse ?assert(?debugFmt("~p is not ~p", [Actual, Expected]))

?debugFmt returns ok, which is not true, so the assertion will always fail.

Alternatively, to use it as a test generator, the entire thing can be put inside ?_assert:

?_assert(Actual =:= Expected orelse ?debugFmt("~p is not ~p", [Actual, Expected]))

1). Open your eunit sources. In my system:

cd /usr/lib/erlang/lib/eunit-2.3.2/src

2). Edit eunit_lib.erl in such way:

diff

54c54
<     format_exception(Exception, 20).
---
>     format_exception(Exception, 99999).

3). sudo erlc -I ../include eunit_lib.erl

4). mv eunit_lib.beam ../ebin

5). Have a good day))

The way I usually achieve this is by having Eunit output XML files (in "Surefire" format, AKA "Junit" format). The XML files have much higher limits for term print depth, and thus probably contain the information you need.

Add this to your rebar.config:

{eunit_opts, 
 [verbose,
  %% eunit truncates output from tests - capture full output in
  %% XML files in .eunit
  {report,{eunit_surefire,[{dir,"."}]}}]}.

Then you can find the results for module foo in .eunit/TEST-foo.xml. I find the files quite readable in a text editor.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!