[erlang-questions] EUnit

Richard Carlsson richardc@REDACTED
Tue Mar 11 20:05:47 CET 2008


Andrew Stone wrote:
> One more question: I put some io:format statements in my setup and
> cleanup functions but they don't show up. Does that mean they aren't
> being run properly? Do I need to run something like 'eunit:setup()'
> first?

Eunit captures all standard i/o from the tests; you won't see the output 
from any normal io:format calls. But there are some useful macros 
defined in eunit.hrl (at the end of the file) that you can use to 
produce nice debug printouts including module name and line number.

These are not only useful while eunit-testing, but can be used for 
arbitrary printf-debugging. They always send the output to the terminal. 
(It seems that I never got around to documenting them, but I should. 
They're pretty straightforward, anyway.)

  ?debugMsg(S)           prints a string
  ?debugHere             prints the current line number
  ?debugFmt(S, As)       prints a formatted string
  ?debugVal(X)           pretty-prints an Erlang term

E.g., ?debugHere produces a message like this:
** modulename: 142: <-

?debugMsg("got here") produces:
** modulename: 17: got here

and so on. If you define NODEBUG before including eunit.hrl, they have 
no effect.

     /Richard



More information about the erlang-questions mailing list