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

RE: [XP] Writing Unit test to existing code

Expand Messages
  • Jason Rogers
    ... Yes. Do you have a more specific question?
    Message 1 of 3 , May 1, 2001
      > I'm working on a project where we are considering using
      > XP. Out project
      > manager one day asked: 'How do you use uni test with our
      > old code?' A
      > good question. Has anyone any experience with writing
      > unit test for
      > existing code.

      Yes. Do you have a more specific question?
    • Arrizza, John
      ... Yes, a fair amount; last year or so on a few small projects and one larger project. My experience has been one of a catch-22: unit tests are easier to
      Message 2 of 3 , May 1, 2001
        > -----Original Message-----
        > From: Anders Bendtsen [mailto:anb@...]
        > I'm working on a project where we are considering using XP.
        > Out project manager one day asked: 'How do you use uni test with our
        > old code?' A good question. Has anyone any experience with writing
        > unit test for existing code.

        Yes, a fair amount; last year or so on a few small projects and one larger
        project.

        My experience has been one of a catch-22: unit tests are easier to write on
        good refactored code, good refactored code can be safely derived from legacy
        code only when you have unit tests in place. One strategy I've taken to
        break the cycle is to use a combination of functional tests and "safe"
        refactorings. I can then get the code in a somewhat reasonable state and
        then add UTs. Even then I add UTs judiciously because of the cost of writing
        them.

        Another strategy that has been proposed is:
        - for a bug:
        - the first time through, just fix the bug
        - the second time in that same area:
        - add UTs (make sure a UT exists that shows the bug failing)
        - refactor
        - fix the bug

        - for an enhancement:
        - add UTs only around the code you're about to change
        - refactor
        - add your enhancement (with UTs and refactorings)

        John
      Your message has been successfully submitted and would be delivered to recipients shortly.