Eunit error messages

Magnus Henoch magnus@REDACTED
Wed Aug 18 14:39:07 CEST 2010


Rick Moynihan <rick@REDACTED> writes:

> I've been using EUnit to do some unit testing; and it seems to work quite well.
>
> However, I'm having a couple of problems, mostly down to the
> legibility of error reports.  In unit testing frameworks I've used in
> the past the assertion functions all took a string to provide a human
> readable description of what the error was, am I right in thinking
> EUnit doesn't support this?  If so, what's the best way to replicate
> this behaviour, I've been manually adding debugMsg's but that's a bit
> messy as I also need to throw an exception to indicate failure.

You can label your tests, as long as they are in EUnit's test
representation:

foo_test_() ->
    {"Testing whether foo is bar",
     ?_test(foo = bar)}.

This gives:

1> foo:test().
foo:7: foo_test_ (Testing whether foo is bar)...*failed*
::error:{badmatch,bar}
  in function foo:'-foo_test_/0-fun-0-'/0


=======================================================
  Failed: 1.  Skipped: 0.  Passed: 0.
error

Is that what you're looking for?

Magnus


More information about the erlang-questions mailing list