Enabling Code Coverage

Visual Studio enables getting information on the amount of code that was subject to the actual test. This can be accomplished by enabling a feature known as Code coverage. To enable it, follow these steps:

1. Select the Test, Edit Test Settings, Local command. This enables editing the current test configuration;

2. When the Test Settings dialog appears, select Data and Diagnostics; then flag the Code Coverage option in the bottom-right part, as shown in Figure 59.5;

Figure 59.5 Enabling code coverage.

image

3. Click Configure. When the Code Coverage Details dialog appears, select the test assembly, which in this case is TestProject1.dll.

Now rerun all unit tests. When completed, the Code Coverage Results dialog shows information on collected results. Figure 59.6 shows the results.

Figure 59.6 Examining code coverage results.

image

You can expand the results to get information on code coverage percentage for single members. For example, both test methods have a 100% coverage percentage against a total 77.78% for the entire project. If you switch to the test code file you notice that Visual Studio automatically highlights lines of code that were subject to test.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.4.181