Subj : Re: Not debugging? To : comp.programming,comp.lang.java.programmer,comp.lang.lisp From : rem642b Date : Fri Sep 02 2005 09:29 pm > From: Russell Shaw > You can only write tests before the code if you are very familiar > with what you want and have thought about it for hours/days/weeks. I disagree with most of that. When unit-testing single lines of code, the test consists of two parts, the data going in, and the data going out. The data going in is already there before I write that one line of code to deal with it. The data going out is immediately checked by eye upon executing that one line of code. No hours/days/weeks of prior thought are necessary to perform that single-line unit test. When unit-testing single functions, the input part is already there before even the first line of code is written, which is long before the function is put together. The output part is already there immediately after the last line of code is tested, which is immediately before putting the function together. That's for the first unit-test for that function. Other unit tests are then constructed immediately after running the first unit test. The whole bunch of them are finished a few minutes after the function is put together. No hours/days/weeks of prior thought are necessary to set up and perform those single-function unit tests. > In the process of making the solution of a very tedious problem clear > to me, i can do a *lot* of throwing away of code and refactoring for > weeks at a time. The amount of extra churn from rewriting unit tests > would be hopeless. I don't see it that way. I test just about every single line of code, and every function, regardless of whether it's a brand-new function or a refactoring of something. Unit testing is no burden, it's how I make sure my code works before I move to writing the next part of my code. > Write code that works, then write unit tests to make sure it > keeps working. So you don't test your code until after you're sure it's working? How can you be sure it works when you havne't yet tested it?? .