Writing unit tests can be hard. It doesn’t help that the built in tools around unit testing haven’t improved as fast as the rest of the IDE in the last few years.
Visual Studio can give coverage numbers but it doesn’t really give context which makes increasing coverage very difficult. Visual Studio and plugins like Resharper can execute tests but modifying code, executing the test suite and checking the results can be slow and cumbersome. There has to be a better way. Fortunately, we have NCrunch.
NCrunch is a Visual Studio plugin which runs your tests in the background and gives you results in near real time so you always know the state of the suite. Better yet, you will now get an indicator showing the coverage and pass/fail of every line of code:
White: Uncovered code
Red: Failing test
Green: Passing test
This allows us to quickly spot uncovered code. In the first week of my team having NCrunch we upped our code coverage by 20% because it was now very visible where we were lacking. It also makes refactoring a breeze because you instantly know when you’ve broken something.
To really appreciate the power of NCrunch though, you need to see it in action so I’ve put together a brief screencast of finding uncovered code, adding a unit test, seeing a failure and correcting it all without saving building or going to “Test Explorer.”
- Easily shows uncovered code.
- Shortens the feedback loop when adding tests or making changes to the code.
- Encourages developers to write more unit tests
- Code can go “green” even though you’re not exercising the code fully.
- Consumes a fair amount of resources and may not be great for older machines.
- Odd licensing, where your key is good through versions based on the date of purchase and upgrade prompts can cause you to install an unlicensed version.
We’ve found NCrunch to be extremely useful and I think you will too.