, ,

There are a lot of examples of how to use eunit. Some use a match expression, which is a concise “built-in” way to wire up some tests. On the other hand, eunit provides the macro ?assertEqual to perform a match test. What’s the difference? It’s deeper than cosmetics and boils down to how much information you need on failure.

The example below is from real code with names changed to protect the guilty.

Match Expression

Using a pattern matching expression only gives the bare minimum error on a failed test. This is probably fine for simple tests.

true = CanDance.
    dance_manager_tests: main_test_...*failed*

Explicit Assertion

Using the macro gives much more color, which I prefer since it tells me where and what the error is.

?assertEqual(true, CanDance).
    dance_manager_tests: main_test_...*failed*
  in function dance_manager_tests:'-can_dance_false/0-fun-0-'/2
About these ads