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

Re: [XP] Testing Leftover

Expand Messages
  • Keith Ray
    ... Please consider doing this exercise (code-kata): 1. Write a bubble-sort class test-first. 2. Then write a quick-sort class test-first. 3. Then refactor to
    Message 1 of 48 , May 31, 2004
    • 0 Attachment
      On May 31, 2004, at 11:51 AM, Gert Kello wrote:

      >> If you were implementing Quicksort, you might find testing very
      >> desirable
      >> at a detailed level. How would you do that?
      >
      > First I'd reconized that I might want to use diffrent sort methods
      > trough similar interface, so I would make an abstract SortBase class
      > which has public non-virtual Sort method and protected abstract virtual
      > PerformSort.
      >
      > Then I make a BubbleSort class, which is derived from SortBase and
      > overrides PerformSort. So, the worker method is protected and I have no
      > problems with testing it...

      Please consider doing this exercise (code-kata):
      1. Write a bubble-sort class test-first.
      2. Then write a quick-sort class test-first.
      3. Then refactor to a common base class.

      If you only write code that is forced to exist by a test, and you only
      refactor to express intent and remove duplication, I don't think you'll
      end up with a public non-virtual Sort method and a protected
      PerformSort in the base class. I think you'll end up with a pure
      virtual public Sort method in the base class. The template-method
      pattern is not necessarily the most appropriate pattern here.

      --
      C. Keith Ray
      <http://homepage.mac.com/keithray/blog/index.html>
      <http://homepage.mac.com/keithray/xpminifaq.html>
      <http://homepage.mac.com/keithray/resume2.html>
    • J. B. Rainsberger
      ... If A behaves correctly, and if testing B with a real A is painful, then consider mocking A when testing B. Simple. -- J. B. Rainsberger, Diaspar Software
      Message 48 of 48 , Jun 2, 2004
      • 0 Attachment
        Lior Fridman wrote:

        > But I want to test class B and not A
        >
        > I know that A behaves correctly (it has its own tests)
        >
        > So I don't think that replacing B with a mock class willl help me test
        > class B.

        If A behaves correctly, and if testing B with a real A is painful, then
        consider mocking A when testing B. Simple.
        --
        J. B. Rainsberger,
        Diaspar Software Services
        http://www.diasparsoftware.com :: +1 416 791-8603
        Let's write software that people understand
      Your message has been successfully submitted and would be delivered to recipients shortly.