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

Does a focus on unit tests lead to violating YAGNI?

Expand Messages
  • JeffGrigg
    I ve been mulling over an idea, and posted on the TDD group: http://tech.groups.yahoo.com/group/testdrivendevelopment/message/33551 I think that an excessive
    Message 1 of 83 , Sep 27, 2010
      I've been mulling over an idea, and posted on the TDD group:
      http://tech.groups.yahoo.com/group/testdrivendevelopment/message/33551

      I think that an excessive focus on unit tests may encourage one to violate YAGNI (You Ain't Gonna Need It) by testing in class/unit functionality that is not needed by the current business functionality.

      Suppose I'm implementing a class that implements some protocol and I notice that it pushes and pops elements from a ten element array -- a "stack." [Let's assume that there's no Stack class in the collections library.] So I Extract Class, creating a ten element Stack that meets my needs. Now due to the nature of the protocol, I never needed an 'isEmpty()' method. But other programmers would think it silly if I built a Stack with no 'isEmpty()' method, so I'll write a test for that, and add the method. And the protocol never overflowed or underflowed the stack, but some people might want special stack-based exceptions for that, as they might want to catch them... so I'll write tests and code for that. I think you can see where this is going. I can think of a number of useful features that a "Stack" should have, which are not needed by the current code, and add tests to "drive out the code."

      On the other hand, I could assume that all the other team members are doing TDD, and if one of them needs an 'isEmpty()' method to make their application functionality work, they'll just add it. With collective code ownership, I don't need to add code that I think someone else might need some day; if they need it, they'll add it right then and there.

      When I focus my TDD testing on the application functionality that is needed by the user, then I'm less motivated to add unnecessary extra functionality. But if I focus testing on unit / class components that will be used to build the application, then I think it's tempting to "fill out" each unit/class with most of the functionality that a reasonable person might expect for its abstraction -- even if some of the functionality does not happen to be needed right now.
    • George Dinwiddie
      Stan, ... Kay gave you some good book recommendations. If you prefer screencasts to books, you might check out http://jamesshore.com/Blog/Lets-Play/ - George
      Message 83 of 83 , Nov 5, 2010
        Stan,

        On 11/4/10 8:17 PM, Stan wrote:
        > * I want to make a personal paradigm shift to full TDD, as in the
        > bowling example you pointed out.

        Kay gave you some good book recommendations. If you prefer screencasts
        to books, you might check out http://jamesshore.com/Blog/Lets-Play/

        - George

        --
        Nov 15-16 Agile Testing Workshop in Orlando
        http://www.sqe.com/AgileDevPracticesEast/Workshop/
        ----------------------------------------------------------------------
        * George Dinwiddie * http://blog.gdinwiddie.com
        Software Development http://www.idiacomputing.com
        Consultant and Coach http://www.agilemaryland.org
        ----------------------------------------------------------------------
      Your message has been successfully submitted and would be delivered to recipients shortly.