简体   繁体   中英

Code coverage test in Visual Studio 2010? How?

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.

I use NUnit as my testing framework and use TestDriven.Net to run VS2010's code coverage. This also works with MSTest ie 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 eg 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 ie Premium or Ultimate.

  1. In Solution Tree, under the Solution Items Folder, create a new Test Settings file . (TestSettings1.testsettings)

  2. In the Test Setting dialog screen, Select Data and Diagnostics on the left. Then check enabled for Code Coverage

  3. On the same screen, double-click Code Coverage , then check the .dlls you want to test. Click Apply.

  4. In the Visual Studio menu, select Test, Run, All Tests in Solution .

  5. Once the test run, in the Visual Studio menu, select Test, Windows..., Code Coverage Results .

Assuming you have a product that supports Code Coverage Analysis (Visual Studio Premium or Ultimate, see more details on their features here ) you can follow the steps listed here:

http://msdn.microsoft.com/en-us/library/ms182534(v=vs.100).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM