?_assertEqual失败时显示完整的预期和价值信息? [英] Showing full expected and value information when ?_assertEqual fails
问题描述
当这个断言失败时,输出被放大为 ... ,我想看到完整的输出,所以我可以发现差异在哪里。
我现在使用 ?debugFmt()作为一个临时解决方案,但我想知道是否有一个替代方案(一个配置选项或参数可以应用于?_ assertEqual()所以输出仅在断言失败时显示。
提前感谢!
编辑:由于 legoscia的答案,我使用测试发生器包含一个测试样本,多个断言:
can_do_something(SetupData) - >
%...一些代码...
[?_assertEqual(Expected1,Actual1),?_assertEqual(Expected2,Actual2)]。
我能想到的最实际显示值在控制台中是这样的:
Actual =:= Expected orelse?assert(?debugFmt(〜p not not〜 p,[实际,预期]))
?debugFmt
返回 ok
,这不是真的,所以断言总是会失败。
或者,使用它作为测试发生器,整个事情可以放在?_ assert
中:
?_ assert(Actual =:= Expected orelse?debugFmt(〜p not not p,[Actual,Expected]))
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)].
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]))
这篇关于?_assertEqual失败时显示完整的预期和价值信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!