There are several tools that my team has grown accustom to using on our .Net projects. Having used them on several projects now, I can’t imagine doing work without them. They are all free, and I think that every .Net developer should give them a shot and try to incorporate them into their own work. They will increase the quality and maintainability of the code that you are producing.
Creating unit tests is the best way I have found to make sure you code accomplishes the task that it is supposed to. I don’t care if you do full test driven development or not, but you need to be writing unit tests for every piece of code you produce. A big benefit to unit testing comes when you need to refactor something. You can make your changes and then run your suite of unit tests to make sure everything is still working correctly.
If all of your unit tests pass, but only 10% of your code is covered by those tests, you code may not be in the shape that you think it is in. That is where ncover comes in. It analyzes the tests you have run against your code and tells you what percentage of the code is tested. There will always be pieces of code that are untestable, but you can normally get coverage of 80% – 90%. NCover is no longer free, but if you follow the link above you can download an older version that is free.
FX Cop is a tool that runs static code analysis against your code to make sure you aren’t violating any commonly accepted rules. When you first run this against your code, you are probably going to get a ton of violations. From there you need to decide what rules are important to you, and only enforce those at the beginning. As times goes you can enforce more and more rules.
SourceMonitor measures the cyclomatic complexity of your code. This is the number of linearly independent paths through your code. Pieces of code that are more complex are harder to test thoroughly and harder to maintain.
CruiseControl.Net is the tool that pulls all of the above ones together. It is a Continuous Integration server. This builds the application after every check in and runs analysis on the code to make sure it adheres to our standards. It executes NUnit, NCover, FX Cop, and Source Monitor. This way you are always aware of the state of your source code.
I would encourage every .Net developer to take a look at the tools listed above and try to incorporate them into your development process. I believe that by using them, you will produce higher quality code that is easier to test and easier to maintain.