Indulging My OCD Using TestDriven.NET With NCoverExplorer

I don’t suffer from classic OCD (Obsessive Compulsive Disorder), but I do sometimes have OCD tendencies. Just ask my poor wife when we’re having dinner while my mind is still trying to resolve a thorny programming problem. Earth to Phil. Are you on this planet?

Lately, the object of my OCD-like tendencies is getting the Subtext unit test code coverage up to 40%. At the time of this writing (and after much work), it is at 38%. Why 40%? No reason. Just a nice round number that we’ve never yet hit. Remember, OCD isn’t necessarily a rational affliction.

If code coverage is my disease, TestDriven.NET with NCoverExplorer integration is my drug, and Jamie Cansdale is my dealer. He graciously gave me a pro license as a donation to the Subtext project.

So here’s the anatomy of a code coverage addiction. First, I simply right click on our unit test project, UnitTests.Subtext, from within VisualStudio.NET 2005 (also works with older versions of VS.NET). I select the Test With menu option and click Coverage as in the screenshot below.

Test With Coverage in VS.NET 2005

After running all of the unit tests, NCoverExplorer opens up with the a coverage report.

NCoverExplorer coverage results in Left Pane

I can drill down to take a look at code coverage all the way down to the method level. In this case, let’s take a look at the Subtext.Akismet assembly. Expanding that node, I can drill down to the Subtext.Akismet namespace, then to the HttpClient class. Hey! The PostClient method only has 91% code coverage! I’ve gotta do something about that!

NCover Drill Down

When I click on the method, NCoverExplorer shows me the code in the right pane along with which lines of code were covered. The lines in red were not executed by my unit test. Click on the below image for a detailed look.

NCoverExplorer Code Coverage Pane

As you can see, there are a couple of exception cases I need to test. It turns out that one of these exception cases never happens, which is why I cannot get that line covered. This may be better served using a Debug.Assert statement than throwing an exception.

If you haven’t played around with TestDriven.NET and NCoverExplorer, give it a twirl. But be careful, this is powerful stuff and you may spend the next several hours writing all sorts of code to get that last line of code tested.

Here are a few posts I’ve written that you may find useful to eke out every last line of code coverage.

Now get out there and test!

What others have said

Requesting Gravatar... Kevin Dente Dec 14, 2006 12:21 PM
# re: Indulging My OCD Using TestDriven.NET With NCoverExplorer
Here here. The TD.NET/NCoverExplorer integration really is astoundingly cool.
Requesting Gravatar... Dave Frank Dec 14, 2006 2:38 PM
# re: Indulging My OCD Using TestDriven.NET With NCoverExplorer
Perchance, wouldst this license be available to *cough* devs on the subtext project? (At your discretion maybe?)
Doing things directly in visual studio is so much nicer than remembering to go launch external programs...
Requesting Gravatar... Jamie Cansdale Dec 16, 2006 6:52 AM
# re: Indulging My OCD Using TestDriven.NET With NCoverExplorer
Thanks for the writeup Phil. :)

Dave, drop me a line via my blog. I'll see what I can do.

I'm planning to add some ASP.NET 2.0 support in the near future. Hopefully that will make life a little easier for .NET web developers.
Requesting Gravatar... you've been HAACKED Dec 18, 2006 7:38 PM
# .NET Developer Charity Auction
.NET Developer Charity Auction
Requesting Gravatar... Dave Donaldson's Blog Dec 21, 2006 7:57 AM
# re: Using TFS for CI: Gotchas
re: Using TFS for CI: Gotchas

What do you have to say?

(will show your gravatar)
Please add 6 and 8 and type the answer here: