NCrunch a Visual Studio Add-In for Unit Testing

I made it a goal late in 2012 that one of my personal task for 2013 was going to be diving deeper into unit testing and mocking.  In my research I came across a unit testing tool for Visual Studio called NCrunch which is developed by Remco Mulder.  I downloaded the trial and immediately fell in love with it.   The rest of this article is a high overview, I highly recommend you check out there site and give it a try.

At first the price of NCrunch can put some folks back ($159 for user license and $289 for seat license), until you look at all the features it packs in, then it becomes a deal.  If you are doing some form of Test Driven Development (TDD) it almost becomes the tool you can’t live without. 

Automated concurrent testing

Normally a developer write code in this form: (if following TDD)

  1. Write the test code
  2. Run the test code (should fail by TDD rules)
  3. Write the code
  4. Run the test code
  5. If the Test passes write another test, else repeat step 3 and 4 till passes.

In a perfect world at the most developers experience 5 steps when writing a test and method of code to go along with it.  What if you could simplify this process even more to something like this:

  1. Write the test code
  2. Write the code
  3. If test passes write another test else repeat step 2 till passes

You might be asking yourself “How the heck are you removing the steps to run the test”.  Simply put you could have a display like below


Ncrunch will automatically run the test in the background on separate threads and as you change code the affected unit test are run.  The results are returned pretty fast, speed can vary depending on your workstation environment and amount of test affected.  In one test on an i7 with 8GB of ram and 15 unit test there was about a 20 second delay in total feedback.    There are two modes for testing, run them side by side (if you have the memory for it) or one after the other.  I choose one after the other when I reach about 10 test (personal preference).

In the bottom right of Visual Studio you will have a Ncrunch status icon that looks like this:


This will provide you with some rapid information about what NCrunch is doing in the background.  In this instance it is showing I have one test that is failing.  If it is blue with a number in it, that means there are test queued up and waiting to run, and a blue N means it is idle.

Code Coverage

As Ncrunch runs the test in the background it will identify the code coverage of your application. Below is an example of what it looks like from the test and source code text editors:


As the test are running the lines of code will show Red for failed test, green for passed test, and black for no code coverage. Each code coverage also has access to a context menu with additional options


Just like other code coverage tools you can see the metrics for your methods.  NCrunch also allows you to ignore classes from the metrics; along with export them to a text file.


Performance Metrics

NCrunch also has performance metrics built in.   As test are run, NCrunch will alert on hot spots by displaying the line dot in yellow.  Hot spots are generally slowly running code, here is an example:


Inline Exception Details

NCrunch will display exceptions inline, this will make it easier to spot test failures


Intelligent Test Execution

As test are run there are metrics collected on system impact.  There is a processing queue system that ranks test (the ranking varies by either test speed or memory this can be set in the settings section).


Included also is a Risk/Progress bar, it will display the metric as your test runs (see the NCrunch support site here for more information on this).


This entry was posted in Visual Studio and tagged , . Bookmark the permalink.