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

UncoveredCode

Red: Failing test

FailingCode

Green: Passing test

PassingCode

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.”

Pros:
  1. Easily shows uncovered code.
  2. Shortens the feedback loop when adding tests or making changes to the code.
  3. Encourages developers to write more unit tests
Cons:
  1. Code can go “green” even though you’re not exercising the code fully.
  2. Consumes a fair amount of resources and may not be great  for older machines.
  3. 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.

http://www.ncrunch.net

Blake Helms

Blake Helms is a .NET Software Development Manager for EBSCO Industries, a global company with businesses in a range of industries including Information Services, Publishing and Digital Media, Outdoor Products, Real Estate, Manufacturing and Distribution, and Business Services, headquartered in Birmingham, Alabama. There he is responsible for several core business applications and has been a driver for software craftsmanship and creating a culture that promotes mentorship and continuous improvement. He is also the cofounder of the Birmingham .NET Meetup with a mission to promote good development practices and .NET technologies in the Birmingham, Alabama area. Blake is incredibly passionate about technology in all areas from writing code for work, to audio/video production for his church to automating his home.