Original article: Visual Studio 2010 unit test-run the test and view the code coverage rate
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