[erlang-questions] I Hate Unit Testing...
Wed Jan 28 15:44:41 CET 2009
Steve Davis wrote:
> 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:
> my_test() ->
> "4" = hex(4),
Hmm. But if you compare the approaches, they are almost the same.
In both cases you create a file to keep the tests in; in both cases
you still have to write the actual assertions/properties; and in both
cases you have to change gear, if ever so little. Writing those two
measly extra lines at the top of the file (when you create it) becomes
less of an obstacle once you've done it a couple of times.
What you _get_ from doing this, however, is much more flexibility
in what sort of properties you can test. If you're not actually
writing code, but merely lists of inputs and outputs, you cannot do
any computations. (That's when you might start to "extend" the input
syntax with expressions, and end up with yet another language...).
And yet, your .app-file examples are practically as verbose as just
writing the tests with eunit. So really, I don't see where you will
be able to save any effort or mental task switching here.
If you want to save the step of creating a separate file, then by
all means place the tests directly in the module you're writing,
as you think of them. Just a simple line of
another_test() -> ?assert(myreverse("abc") =:= "cba").
and you're done. That's about as much work as inserting a comment.
Add the include directive while you're having some coffee, compile,
and run the tests.
However, some direct eunit support for reading a comma-separated list
of functions and input/output values could be handy. I'll add that to
my feature list.
More information about the erlang-questions