Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing full expected and value information when ?_assertEqual fails

Tags:

erlang

eunit

I'm coding a unit test where a (rather lengthy) binary is generated, and I want to assert that the generated binary equals the one I expect to be generated. I'm running eunit through "rebar eunit".

Thing is, when this assertion fails, the output is abreviated with "...", and I want to see the complete output so I can spot where the difference is.

I'm now using "?debugFmt()" as a temporary solution, but I'd like to know if there's an alternative to it (a config option or argument somewhere that can be applied to "?_assertEqual()" so the output is only shown when the assertion fails).

Thanks in advance!

EDIT: Due to legoscia's answer, I'm including a test sample using a test generator, with multiple asserts:

can_do_something(SetupData) ->
    % ... some code ... 
    [?_assertEqual(Expected1, Actual1), ?_assertEqual(Expected2, Actual2)].
like image 775
marcelog Avatar asked Jun 08 '12 16:06

marcelog


1 Answers

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]))
like image 108
legoscia Avatar answered Sep 22 '22 05:09

legoscia