Question

I am using VS2010 + C# + .Net 4.0. I want to do code coverage for unit tests. I have two choices after investigating, my question is, I want to know the pros and cons of such two tools/choices.

  1. Using non-VS built-in tools, like ncover;
  2. Using VSTS built-in tool, for example,

http://msdn.microsoft.com/en-us/library/dd299398%28VS.90%29.aspx

http://msdn.microsoft.com/en-us/library/ms379625%28VS.80%29.aspx#vstsunittesting_topic7

Was it helpful?

Solution

Having used both tools, they both work pretty much the same way. You run your tests and then you view the report. Both tools provide code highlighting to show, which lines of code have coverage and which ones do not. MsTest does not provide much more in terms of information, but NCover provides lots of HTML reports and can trend code coverage over time. These sorts of things can be helpful.

Now for the differences. The MsTest coverage tools really only work with MsTest unit tests. It cannot easily cover tests written using NUnit (or other testing frameworks) from the IDE. It can be done, but takes some time and requires invoking the coverage tools from the command line and instrumenting your assemblies manually. Again, it can be done, but not very easily, especially for a beginner. NCover is more flexile and can be run with most testing frameworks. Also, I have found that it is easier to run NCover with an automated build server. I never had much luck automating MsTest coverage in CruiseControl, but I am guessing MS makes it work in Team Foundation Server.

OTHER TIPS

Just a couple of small notes that might be helpful:

  1. Unfortunately, the freeware version of NCover does not work with the .Net 4.0 runtime
  2. If you're interested in intgration with CruiseControl.Net, you can use the Gallio test runner to run the MSTest tests. See Gallio: Cannot run tests because the MSTest executable was not found
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top