I can’t remember exactly what drove me to seriously look into it, but for the last two weeks, I’ve been using NCover to calculate the coverage of my unit tests. Boy, am I glad I finally did. I’ve added it to the list of Apps I Use Everyday, and you should too. You shouldn’t use the xsl file it gives you, though: it sucks; use this xsl file instead, by Yves Lorphelin. A good overview of how to setup NCover can be found here, as well as a preview of the good xsl file in action. I think my biggest beef with NCover is the pain involved in setting the damn thing up. I had to put both NCover and NUnit program directories in my path for it to start working. I also tried CoverageEye.NET, but I could not get the damn thing to work. There is almost no documentation for setting it up. But there is a good comparison of the two here; he likes CoverageEye better.
As far as I can tell, NCover is the best free tool that doesn’t muck up you’re project settings. (There is another code coverage tool called NCover at sourceforge that requires you to add a reference to it to use it. Um, no thanks.) Another thing I don’t like is there is no GUI. I’m a GUI guy: I like to look at pictures, shapes, you know: shiny shit; I’m a visual animal. However, I’m not entirely out of luck though: Jeff Key has written a quick little GUI wrapper for NCover. But, alas, I couldn’t get it to work either: It always throws a PathNotFoundException, even after I got NCover working on the command line. And, I note, found in my Google research for this post, and put here for future reference, that he has posted another NCover oriented tool: NCover Browser. I haven’t looked at it yet, but I will soon.
When I started with NCover, we had about 80% of our code covered by unit tests. It took about a day, maybe a bit more, to get that up to hover around 90%, where it sits now. I was surprised it took so long to get what seemed like an insignificant jump. I’m noticing that much beyond 90% isn’t providing much benefit. In other words, the effort of writing the test is not worth the benefit having the test gives me. So my goal now is to stay around 90%. Now that I’m using this tool, I’m finding that I write tests that cover all paths through a method automatically, making my efforts a tad more focused and efficient.
One thing that becomes glaringly obvious with this tool is that overriden GetHashCode() methods NEVER get called. In fact the only reason I override it is the warning I get if I override Equals() but not GetHashCode(). Consequently, I just call base.GetHashCode(). That’s one thing I’ve wondered about for a while. Anybody know?