How to: Gather Code-Coverage Data with Generic Tests
People usually associate code-coverage data with unit tests. But you can gather code-coverage data on code in any binary file that has been instrumented to provide such data. This includes instrumented assemblies or binary files that are called by an application that a generic test wraps. Follow the steps in Gathering Code-Coverage Data to gather code-coverage data while you run a generic test.
Gathering Code-Coverage Data
You can gather code-coverage data when you test production code in a binary file that is wrapped into a generic test. To do this, you instrument that binary file, as described in the following procedure.
To gather code coverage data with a generic test
In Visual Studio, open the test project that contains your generic test.
In Solution Explorer, open the Solution Items folder.
In the Solution Items folder, double-click the .testrunconfig file.
The test run configuration dialog box is displayed.
Click Code Coverage.
Under Select artifacts to instrument, select the production-code binary file for which you want to collect code-coverage data.
If the binary file is not displayed under Select artifacts to instrument, click Add Assembly. In the Choose Assemblies to Instrument dialog box, specify the binary file, and then click Open.
The binary file that contains your production code might not be the file you wrapped in the generic test. Sometimes, you specify that your generic test should wrap an intermediary application as a test harness. This test harness, in turn, runs the production code that you are testing.
Click Apply, and then click Close.
Now, when you run the generic test, code-coverage data is gathered. For more information on obtaining and viewing code-coverage data, see.