dotNetDave Says… If Your Code Is Hard To Unit Test, You’re Doing It Wrong

Unit testing is something very important for any project. With that said, I rarely see it done in projects or done correctly. How can you push the code to quality assurance or production without knowing the state of the code?
 

A few years back, I worked on a contract at a company here in San Diego, California in the US. The two managers came to me after I started and said they were going to give me access to the production servers so I can push code. I asked them if there are unit tests for the projects. They said no. So I told them I don't want to be responsible for pushing to production unless there are. I didn't last there very long (for other reasons too).

Let's face it, I don’t think anyone wants to write unit tests, they aren’t features and they don’t sell product. But, they are very, very important. From talking to people who work at Microsoft, try to make it a goal to have at least 75% of code coverage. Look at it like going to the doctor for a check-up. Sure, I don’t think anyone looks forward to it, but it needs to be done to know the state of your health. Unit tests are the same thing.

Does your code have 75%+ unit test coverage? Please make a comment below. 
 
Next Recommended Reading Quick Tips for writing Clean Code Part-1

McCarter Consulting
Software architecture, code & app performance, code quality, Microsoft .NET & mentoring. Available!