Thursday, August 03, 2006
Use the tool, tool part 3
According to 'Working effectively with legacy code', any code without unit tests can be considered legacy code. That means pretty much every piece of software I've ever worked on is legacy code.
Before .NET, writing unit tests was hard. In my Delphi days I tried to use DUnit but the language didn't lend itself to writing a tool that was simple to use. In .NET, attributes and reflection make it much easier. So we have NUnit, which has been the tipping point for me writing unit tests.
As well as testing functionality, unit testing also helps validate the design of a system. If it's hard to write tests for your classes, chances are the design isn't too great. It suggests too much coupling and cohesion between the classes.
Unit tests are always mentioned in the context of agile development, but there is no reason why they can't be used without adopting the whole philosophy. I have my doubts about some of the agile approach but I still believe unit tests are worthwhile. In the short term, they certainly add time to the development process, but I believe in the long run they save time and improve code quality. Of course management are often more interested in the short term (understandably since in the short term bills have to be paid), so unit tests may be a hard sell.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment