Loading ...
Sorry, an error occurred while loading the content.

Re: [XP] Threshold of Minimal Unit Testing

Expand Messages
  • J. B. Rainsberger
    ... If a method is public, but not being used, then there is a design problem. Try making the method private for a while to see what happens. If a test for the
    Message 1 of 10 , May 1 8:54 AM
    • 0 Attachment
      Scott Bellware wrote:

      > --- In extremeprogramming@yahoogroups.com, Ron Jeffries
      > <jeffries@d...> wrote:
      >
      >>On Thursday, April 29, 2004, at 3:50:39 PM, Scott Bellware wrote:
      >>
      >>
      >>>When is it acceptable to NOT test properties and methods that
      >
      > have
      >
      >>>public visibility?
      >>
      >>Um, whenever they couldn't possibly be wrong? Whenever they are
      >
      > tested
      >
      >>indirectly? Whenever it doesn't matter whether they don't work?
      >>
      >>Do you have a situation or example in mind?
      >
      >
      > I suppose I'm interested in a couple of things:
      >
      > 1-) Public methods. When these are tested indirectly, should I not
      > also test them directly? After all, they are public, and can be
      > called in a sequence other than the sequence found in the indirect
      > test. It also occurs to me that some of these methods that are
      > called indirectly may be candidates for having their visibility
      > changed to private if they are only ever going to be called
      > indirectly.

      If a method is public, but not being used, then there is a design
      problem. Try making the method private for a while to see what happens.
      If a test for the method is easy to write, I might just go ahead an
      write it, but especially if the method arose out of refactoring, it
      ought perhaps to be private until proven needed.

      > 2-) Properties. If a setter triggers some validation code which
      > causes an exception to be raised, I image I should test for possible
      > failure modes. Should I also go ahead and test for non-failure
      > modes? Should I test a property that is read/write just to ensure
      > that I'm reading and writing to the same private member? I have in
      > fact edited property property code so that it would read and write
      > from and to different underlying private members. I know it's a
      > boneheaded thing to do, but it happens - and not just to stoned
      > idiots :)

      Nice that some people permit and even appreciate hyperbole. It's rarer
      in these times. :)

      Certainly, if a property-access method does something more than just
      read/write a field, then it's not a bad idea to test that behavior; but
      as Ron usually says, if the property is necessary, then it will be
      tested somewhere, and that will be good enough; and if it is not tested
      somewhere, then it is not necessary, and who cares whether it breaks?
      (In fact, remove it!)

      Take care.
      --
      J. B. Rainsberger,
      Diaspar Software Services
      http://www.diasparsoftware.com :: +1 416 791-8603
      Let's write software that people understand
    • Daniel Poon
      ... What if you don t understand the method you are supposed to be testing?
      Message 2 of 10 , May 1 11:47 AM
      • 0 Attachment
        > When is it acceptable to NOT test properties and methods that have
        > public visibility?

        What if you don't understand the method you are supposed to be testing?
      • James Cloughley
        Then I d definitely write tests for it. I find this especially useful when I encounter someone else s code that lacks unit tests. Writing the tests help you
        Message 3 of 10 , Jun 2, 2004
        • 0 Attachment
          Then I'd definitely write tests for it. I find this especially useful when I encounter someone else's code that lacks unit tests. Writing the tests help you understand what the method is supposed to do.

          Jim

          -----Original Message-----
          From: Daniel Poon [mailto:dan@...]
          Sent: Saturday, May 01, 2004 2:47 PM
          To: extremeprogramming@yahoogroups.com
          Subject: Re: [XP] Threshold of Minimal Unit Testing


          > When is it acceptable to NOT test properties and methods that have
          > public visibility?

          What if you don't understand the method you are supposed to be testing?


          To Post a message, send it to: extremeprogramming@...

          To Unsubscribe, send a blank message to: extremeprogramming-unsubscribe@...

          ad-free courtesy of objectmentor.com
          Yahoo! Groups Links
        • Michael Feathers
          JC Then I d definitely write tests for it. I find this especially useful when I encounter someone else s code that lacks unit tests. Writing the tests help
          Message 4 of 10 , Jun 2, 2004
          • 0 Attachment
            JC> Then I'd definitely write tests for it. I find this especially useful when I encounter someone else's code that lacks unit tests. Writing the tests help you understand what the method is
            JC> supposed to do.

            Or better yet, what it really does.

            Michael Feathers
            www.objectmentor.com
          Your message has been successfully submitted and would be delivered to recipients shortly.