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

[XP] Re: TDD - Test Passes before code was wrote...

Expand Messages
  • geoffrey_slinker
    ... should have ... told me ... because the ... that there ... failure ... Sorry, I didn t post the full context of my other conversation. ... The
    Message 1 of 31 , Nov 1, 2005
      --- In extremeprogramming@yahoogroups.com, Brian Slesinsky
      <brian@s...> wrote:
      >
      > On 10/31/05, geoffrey_slinker <geoffrey_slinker@y...> wrote:
      >
      > > You expect that when writing new code you would get a compile
      > > error because the things the test call do not exist.
      >
      >
      > Actually, when I do it I don't expect a compile error because I
      should have
      > already created the stub for the new method. (IntelliJ should have
      told me
      > about any missing methods.) I expect the test to fail at runtime
      because the
      > stub is present but doesn't do anything. Running the test ensures
      that there
      > are no lurking compile errors in the code and that the test's
      failure
      > message is meaningful before I move on to the next phase.
      >
      > - Brian
      >

      Sorry, I didn't post the full context of my "other" conversation.

      Here is what got me onto this topic:

      ----
      The Test-Code-Simplify cycle (Quoted verbatim from "Extreme
      Programming Applied", p159)

      Write a single test
      Compile it. It shouldn't compile, because you haven't written the
      implementation code it calls

      Implement just enough code to get the test to compile
      Run the test and see it fail

      Implement just enough code to get the test to pass
      Run the test and see it pass

      Refactor for clarity and "once and only once"

      Repeat
      -----

      Notice that the quote shows taht they expected the compile to fail.



      Geoff
    • J. B. Rainsberger
      ... Yes. My underlying assumption was that, when running the test, I didn t expect it to pass. Sometimes I write tests that I expect to pass -- or at least
      Message 31 of 31 , Nov 7, 2005
        Chris Wheeler wrote:

        >>I've had this happen a number of times. When it does happen, either:
        >>
        >>1. My test is wrong, or
        >>2. I had written speculative production code, or
        >>3. I'm having a very bad day
        >
        > You frame this happenstance in a negative light. I've experienced cases
        > where I was asked to see if the system did something, and because the design
        > was simple and effective and correct, it passed the test immediately.
        >
        > It's a great feeling, it doesn't happen often, but it does. One should
        > expect that their systems and designs behave like this once in while because
        > good designs are about discovery, and sometimes we discover that our design
        > actually does a little extra - including working under a condition that we
        > didn't expect it to work under.

        Yes. My underlying assumption was that, when running the test, I didn't
        expect it to pass. Sometimes I write tests that I expect to pass -- or
        at least have reason to believe might pass -- for exactly the reason you
        cite.

        In general, though, I expect the new test to fail. When it doesn't, I
        start out suspicious, then try to rule out the negative cases I cited
        above. If none of those explanations work, then I must simply have
        (happily) accidentally got it right. I'm just not ready to let that be
        my default reaction.

        --
        J. B. (Joe) Rainsberger
        Diaspar Software Services
        http://www.diasparsoftware.com
        2005 Gordon Pask Award Winner for contribution to Agile practice
        Author, JUnit Recipes: Practical Methods for Programmer Testing
      Your message has been successfully submitted and would be delivered to recipients shortly.