views:

458

answers:

1

Hello, I have a simple project on C#.NET and have written it in Visual Studio 2010. I am a newbie in C# and Visual Studio.

I have written some unit tests, and they pass ok, but how can I test code coverage?

Thanks in advance.

+1  A: 

I use NUnit as my testing framework and use TestDriven.Net to run VS2010's code coverage. This also works with MSTest i.e. Visual Studio tests. First you need to get hold of TestDriven.Net:

http://www.testdriven.net/download.aspx

Once TestDriven.Net is installed, you will get some extra items added to your Solution Explorer context menu e.g. right-click a project and you'll have some TestDriven options under "Test With". One of those options is "Coverage" which will run your unit tests with code coverage and then display the code coverage results window. Works very well.

Update

Of course you can only get code coverage in Visual Studio 2010 if you have a version that actually supports it i.e. Premium or Ultimate.

chibacity
Note that the VS/MSTest *coverage* tools are not included with all VS SKUs (or at least, it didn't used to be). TestDriven,NET can't use them if they aren't in the installed edition.
Marc Gravell
Ah yes, good point. I hadn't thought about that. I am using Ultimate so I get all the bells and whistles. :)
chibacity
Likewise ;p But worth mentioning...
Marc Gravell