[erlang-questions] I Hate Unit Testing...

Dan Milstein dan.milstein@REDACTED
Wed Jan 28 15:30:46 CET 2009

Maybe I'm even lazier, but I just write my tests in the same file as  
the module under test, so then the boilerplate is (within the file  
you're testing, and therefore already compiling):


So then, when you re-compile the module, instead of, well, whatever  
else you were doing, just do:

 > module:test().

[If putting tests in that same module is somehow Wrong And Terrible,  
world, please let me know why... ]

In addition, eunit's ?debugVal() macro is incredibly useful -- it's  
like the keystroke-friendly print stmt that Erlang doesn't have.  In  
other words, one of your tests fail -- want to look at what's going on  
inside the middle of a function somewhere?  Just wrap a line in ? 
debugVal() and you get a *great* info message, with full line number  
and everything.  It's so useful I sometimes -include eunit just to get  
access to that during my dev process.

Just my $.02 as a test-obsessed programmer: eunit is as impressively  
close to the ideal of As Simple As Possible as anything I've ever seen.

(Speaking of which, Richard, eunit is absolutely the bomb -- I adore  

-Dan M

On Jan 28, 2009, at 9:12 AM, Steve Davis wrote:

> Hi Richard,
> Thanks very much for your thoughts.
> Richard Carlsson wrote:
>> Honestly?
> Honesty is always at the heart of the most useful feedback!
>> simplest possible use of eunit for the terminally lazy...
> I've used JUnit and NUnit and indeed EUnit too. The real issue is "how
> much" I use them... or don't. All these frameworks are super-powerful
> and well featured BUT they all require coding (including Quviq's  
> solution).
> That *is the barrier* to me (and apparently most coders) bothering  
> with
> unit tests when stuck in the heat of things.
> I really am that lazy (or maybe just that stupid) that I don't want to
> change gear into writing (and debugging) a test module. Even when I do
> actually pull my finger out, I generally delay doing it by which  
> time I
> have forgotten half of what the module was really intended to do (i.e.
> the detail of the spec), and so I have to remember all that and it
> becomes a big chore.
> OTOH, I *may* be bothered to add to a text file:
> hex(4) = "4"
> But from experience, I know that I'll just not bother to write:
> -module(test_myapp).
> -include_lib("eunit/include/eunit.hrl").
> my_test() ->
>     "4" = hex(4),
>     ...etc
> On another note, someone mentioned Cucumber... well hmmph. That's all
> very nice for your corporate stakeholders, but it's waaaaayyy too
> verbose for any developer I know to be bothered with.
> With respect,
> /s
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list