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

9191Re: [XP] Testing experiences

Expand Messages
  • Kevin Smith
    Jul 31, 2000
      >Being JustaProgrammer and new to XP, I have started trying to make sense of
      >testing, since it is the practice that seems to require most adjustment and
      >seems least dependent upon other practices. You could say it's a good
      >methodology "spike" for trying to use XP.

      Welcome, and thanks for asking a"real" xp question to distract us away from
      Einstein and machine parts.

      >tests: I feel that my code is too tightly coupled, so I guess breaking it
      >apart is a useful practice with or without the testing. I also I have no
      >idea about how many tests I should have, their granularity, and how
      paranoid
      >I should be in my testing.

      Absolutely. Probably the single biggest code change for most people would be
      to move to an MVC or Doc/View system, where the UI is not coupled with the
      logic. If you can do that, you stand a pretty good chance of having testable
      objects and/or methods in your model/doc layer.

      It is also often helpful to split your persistence (database) stuff into a
      separate layer. This allows you to create test stubs of your db access
      functions, which means you can pretend to do reads and writes without really
      doing them. Great for testing the upper layers.

      The other thing that kills unit testability is globals. The more you rely on
      some grand external "state", the harder it is to write a little test that
      just checks the functionality of one little function. Globals are evil.

      How many tests? I think I have heard a rule of thumb that each non-trivial
      public function (method) should have a test. The tests should aim for
      complete coverage of all the code paths of both the public function and each
      private function. For each class I create, I tend to create a corresponding
      tester class.

      Kevin
    • Show all 66 messages in this topic