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

TDD Like You've Never Seen it Before

Expand Messages
  • John A. De Goes
    A short screencast showing myself and two other developers TDD ing a Stack in the Java programming language: http://www.vimeo.com/1653402 I think it makes a
    Message 1 of 67 , Sep 2, 2008
      A short screencast showing myself and two other developers TDD'ing a
      Stack in the Java programming language:

      http://www.vimeo.com/1653402

      I think it makes a good introduction to test-driven development,[1]
      and shows how following TDD strictly leads to test coverage of all
      code paths. You can download the source code from http://www.n-brain.net/outbox/una-tdd-stack.zip

      We used UNA 1.1 and the newly-released Java 5 Mixin for UNA, which
      integrates open source tools like Infinitest and JUnit into UNA.

      Although we used text chat for this tutorial, if you were doing
      serious development, you would likely be collocated or use voice chat.

      A note to help you follow along: UNA has been configured so that
      whenever a file is saved, the code is compiled, and if compilation is
      successful, then the relevant tests are re-run using Infinitest (and
      if the compilation is not successful, errors/warnings appear directly
      in the offending documents). This happens on all developers' machines,
      because the configuration is done via "Team Tools", which are
      accessible to all members of the team.

      This turns "Save" into a kind of "I think I'm ready" button, where
      both the compiler and the automated tests let you know if you really
      ARE ready. I highly recommend that UNA be configured in this way with
      any language, not just with Java, and we'll be releasing a PHP mixin
      in the near future which does just that for PHP (though it's pretty to
      easy to do the same for any other language).

      Comments are welcome!

      [1] The tutorial doesn't really showcase the "design" benefits of TDD,
      as stacks are well-defined. A larger or less-well-defined scenario
      would better demonstrate design benefits.

      John A. De Goes
      N-BRAIN, Inc.
      http://www.n-brain.net
      [n minds are better than n-1]
    • Jeff Grigg
      ... I m not sure about the good introduction training aspect of starting with the target class and method shells, and then writing tests. I would consider
      Message 67 of 67 , Nov 13, 2008
        --- "John A. De Goes" <john@...> wrote:
        > A short screencast showing myself and two other developers
        > TDD'ing a Stack in the Java programming language:
        >
        > http://www.vimeo.com/1653402
        >
        > I think it makes a good introduction to test-driven
        > development, [1] and shows how following TDD strictly
        > leads to test coverage of all code paths. You can
        > download the source code from
        > http://www.n-brain.net/outbox/una-tdd-stack.zip

        I'm not sure about the "good introduction" training aspect of starting
        with the target class and method shells, and then writing tests. I
        would consider this an "acceptable" TDD approach, but not pure, and
        not the approach I take when teaching TDD.

        Overall, I would call it a successful TDD session. And an interesting
        tool.

        _ _ _ _ _


        I'll push the refactoring another two or three steps:

        #1. I don't like duplicate data.

        So I killed the 'private volatile int size;' property, giving...

        public int size() {
        int size = 0;
        for (Node<T> node = head; node != null; node = node.getNext())
        ++size;
        return size;
        }

        public boolean isEmpty() {
        return (head == null);
        }

        [and a few more deleted lines]

        If you want efficient, add a test for it. (...that 'Node.getNext()'
        isn't called N times.)


        #2. Simplify 'push'...

        from
        public void push(T value){
        if (head == null) {
        head = new Node<T>(value, null);
        }
        else {
        Node<T> oldHead = head;
        head = new Node<T>(value, oldHead);
        }
        }

        to
        public void push(T value){
        head = new Node<T>(value, head);
        }


        #3. Delete the default constructor. Java generates one.

        IE:
        public Stack() {
        }


        There. Better now? ;->
      Your message has been successfully submitted and would be delivered to recipients shortly.