I’m sure you’ve heard everyone screaming in your ears that you should be unit testing your code and how important it is. Well I’m hear to add to that chorus, but I would like to let you know when it really clicked for me personally.
I am a curator of a few open source projects, and I want to make sure that I am continually innovating and adding features. At the same time, I know that thousands of developers (what nuget tells me) are depending on me not screwing things up. Screw ups are inevitable, but screwing up and being careless are two different things. That is why I make sure my libraries / frameworks have at the very least a dependable test suite that I can run or users can run. I also want users to contribute, and I have to make sure that any work they do doesn’t hurt the thousands of other users. So in my case, fear is a huge motivator.
When I first started unit testing I was heavily dependent on NUnit and the ReSharper test runner. Although ReSharper is a great tool, it requires manually starting your tests. So what’s wrong with manually starting your tests? Well personally, I sometimes find myself in code trances and realize I just altered major parts of the code, or added substantial branching logic. Running my tests manually usually came too late, as I would see many tests were now failing. How the heck do I now find the offending code, fix the failing tests, and maintain the feature I just added. It is a daunting task for many developers and usually the reason they give up on unit testing. How many have heard “Oh yeah, I commented that test out cause it was failing”?
Fast forward to NCrunch, a continuous test runner for Visual Studio. It is a Visual Studio plug-in that runs your unit tests every time your modify code. Any change to your code will instantly tell you if all your tests still pass, fail, or if the code is even covered by your unit tests. How amazing is that?! Some scenarios where this is critical to my workflow are as follows:
- Merging a pull request.
- Adding a new feature.
- Refactoring code
Does this look like your workflow?
It is very satisfying to know that additions have not compromised the code base, and it is even better when that feedback is immediate.
If you’ve been scared of unit testing or just have reservations, please give NCrunch a try. You’ll be amazed at how good it feels and how helpful it will be to you and your fellow developers.