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

[extremeprogramming] Re: (OTUG) Test First Design

Expand Messages
  • Brad Appleton
    ... Well - Meyer will of course tell you that tests are definitely not a better place for the invariants. He will religiously claim that invariants are a
    Message 1 of 3 , Jan 5, 2000
    • 0 Attachment
      On Wed, Jan 05, 2000 at 04:51:17PM -0600, Robert C. Martin wrote:
      > It occurs to me to wonder if unit tests are a better place for those
      > invariants than the source code itself. That is, should contracts be
      > separate from the actual source code, or would we be better off merging
      > them as in Eiffel? I'm partial to the unit test approach, but I'd like
      > to hear what others think?

      Well - Meyer will of course tell you that tests are definitely
      not a better place for the invariants. He will religiously claim
      that invariants are a rightful part of the *interface* declaration
      of any method and must not be separate. I'd be surprised if he has
      any objection to having separate unit tests which exercise those
      invariants.

      I do think its wrong to view the unit-tests as if they were the
      invariants. They aren't. They help flesh them out, but they aren't the
      same thing. If you've ever programmed in Eiffel for any non-trivial
      class or method, you will quickly realize that getting the invariants
      and the pre and post conditions correct can also be a very tricky thing
      (often trickier than the rest of the method if one is in the habit of
      writing very short methods).

      The unit-tests can help you flesh out the correct form of the intended
      assertions. They do not constitute the explicit expression of what those
      assertions are. It different to have a test that tells you if 5, and 10,
      and 15 are valid inputs. Its another thing altogether to say anything
      not-divisible by 5 is invalid.

      I'm inclined to agree with Meyer in that I strongly prefer to see
      the invariants and pre/post conditions as part of the interface.
      You can still have unit-tests (and without being redundant, so
      you can still say them once and only once).
      --
      Brad Appleton <bradapp@...> http://www.enteract.com/~bradapp/
      "And miles to go before I sleep." -- Robert Frost
    Your message has been successfully submitted and would be delivered to recipients shortly.