From: James Britt Date: 2004-08-24T00:07:30+09:00 Subject: Re: How to check syntax Andreas Schwarz wrote: > Graham Nicholls wrote: > [...] > >> As you can see, theres not much to it - an hours work or so - I'd >> rather not >> have to spend much time writing testing - ISTM its easier to fix a bug >> when >> it rears than spend ages trying to eliminate all possible bugs > > > Your example seems to be very easy to test; feed it a few different > files and compare the output to the expected result. This is especially > helpful to make sure that you break anything when you change the code. Bugs may not rear their heads until some notable damage is done in a production setting. Unit tests do more than help trap syntax errors or demonstrate that the code will actually run. The help show that your code is really doing what you intended it to do, not just what you told it to do. (This is not only an issue for so-called "scripting" languages; successful compilation of statically-typed code won't tell you if the program is well-behaved, only that you have served the gods of syntax.) When you *do* find a bug in production code, unit tests help you make the fix without introducing new problems. I find that this is where tests offer the biggest the benefit. (Well, that and helping to guide API design.) As code grows, tests help speed up development by providing near-instant feedback, which helps keep you from introducing subtle execution errors that are time-consuming to track down. James