Visual Studio 2010 unit test-run the test and view code coverage

Source: Internet
Author: User
Tags visual studio 2010

When you run the test and view the code coverage rate, you can collect the code coverage data to view the code part of the project being tested.

Run the test and view the code coverage
Note the solution name in Solution Explorer. Assume that the solution name is cunittest. This solution contains the test code.
1) under solution items in Solution Explorer, double-click Run Configuration File Local. testsettings. The "test Settings" dialog box is displayed.

2) Click "data and diagnosis" and select "code coverage ". Double-click "code coverage ".
3) under "select project to be checked", select the box next to addtest. dll. Its path indicates <solution directory> \ addtest \ bin \ debug.


4) in the dialog box, click Save As, and then click Save ". A message box appears asking if you want to save the existing file. In the message box, click yes to replace the existing file.
5) on the "test" menu, point to "select Current Test Settings ". The sub-Menu displays all test settings in solution. Place a selected Tag next to the recently edited running configuration (local. testsettings) to make it the current test setting.


6) in the test List editor, select "addtest" and "dectest", and click "Run selected test ". Run this test.

7) on the "test tool" toolbar, click "code coverage result ". The "code coverage result" window opens.

8) the "hierarchy" column in the "code coverage result" window shows a node that contains all the code coverage data obtained during the latest test. The name of the test node is in the format of <user name >@< computer name> <date> <time>. Expand this node.
9) Expand the Assembly addtest. dll node, namespace addtest node, and dectest class node. The columns in this table display the coverage statistics of each method, class, and the entire namespace.


10) double-click the row where the method is located. Open the programtest. Cs source code file and locate the location of the method. In this file, you can see the highlighted effect of the Code. The lines highlighted with light blue have been executed during the test, and the lines highlighted with light brown have been partially executed, the code lines highlighted in Brown have not been executed. You can scroll to view the coverage of other methods in this file.

Visual Studio 2010 unit test-run the test and view code coverage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.