From: Phlip Date: 2008-08-03T01:33:54+09:00 Subject: Re: unit testing advice Shadowfirebird wrote: > I certainly "get" the idea that it's better to write the tests first. > Unfortunately my dinosaur brain needed to write some code to prove > that my class model was workable...! > > What I'm seeing quite clearly now, is that the next best thing is > writing the tests while *pretending* that you haven't written the code > yet. Right: It's like a little conversation between the tests and code, line by line. > I suppose you are all going to say that the tests should show what the > code is supposed to do? I really like that idea... The absolute ideal situation: - write a little test (maybe add one line to an existing test case) - run the test, and its diagnostic tells you what to do next - do it - run the test and pass it - integrate! - write a little bit more test - it fails, and tells you what to do next - do it - the test fails again, telling you the _next_ thing to do! - do it - the tests pass - integrate! The best way to do TDD is make the tests tell you each thing to do next. But if you can't _easily_ get back to a green-bar, you should revert back to the last integration. You should always be able to predict the result of the next test run. -- Phlip