Tim Bates wrote:
> You're right, that's a really stupid example, and I was hoping nobody
> would spot it. :P I tried to think of a better example, and failed,
> since my original example (`attr_accessor :date`) is so trivial as to
> not need unit testing. (Although the unit testing gurus may disagree
> with me, I tend not to write tests for attributes unless I have written
> extra code in them - I just assume that attr_accessor does what it's
> supposed to.)
>
>> I think it would be more convincing to talk about unit tests covering
>> the correct overall operation of the class under scrutiny, rather than
>> examining some lowly accessor.
>
> That's right, and the problem arises because the whole article revolves
> around writing an accessor method - partly because it's simple, and
> partly because that was what I was trying to write when I started the
> discussion on #ruby-lang. :) If you can think of a better example, I'll
> happily rewrite it.

Well, there's the problem.  There's no context for the attribute, so
conjuring an example of a meaningful unit test is difficult. [1]  If you
want an example for the unit test, you need an example for the class
surrounding the accessor.  That would probably enhance the article anyway.

Assuming we don't have this magic example, I propose you leave out the bad
one, and focus instead on arguing the point: that good unit tests

 * raise confidence in the ability of the class to perform its function,
   rather than focusing on the minor details

 * demonstrate the behaviour of the class under the full range of normal
   ("acceptable") input, and thus serve as practical documentation to an
   extent

But such an argument would obviously benefit from a good example :)

Cheers,
Gavin

[1] I've yet to read an example of unit testing that isn't fairly
convoluted anyway - references, anyone?