From: Tim Bates Date: 2004-05-18T09:17:13+09:00 Subject: Re: How to duck type? - the psychology of static typing in Ruby Gavin Sinclair wrote: >>10: def test_date >>11: @obj = Foo.new >>12: @obj.date = MyClass.new.notadate >>13: assert(@obj.date.respond_to?(:year)) >>14: end > > > > Now I'm no unit testing guru (I try...) but that test to me seems so > trivial as to be pointless. Since the code it's testing does > absolutely nothing other than assignment, you're not testing the > *code*, you're testing one possible input value. 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. > # But your psychological needs could differ from mine :) No, they don't. You're absolutely correct, that unit test is so trivial as to be pointless. I don't bother to test attr_accessor either. > The rest of the article's good, though. Thanks. :D Tim. -- Tim Bates tim@bates.id.au