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

  1. In Visual Studio, open the test project that contains your generic test.

  2. In Solution Explorer, open the Solution Items folder.

  3. In the Solution Items folder, double-click the .testrunconfig file.

  4. The test run configuration dialog box is displayed.

  5. Click Code Coverage.

  6. Under Select artifacts to instrument, select the production-code binary file for which you want to collect code-coverage data.

    Note

    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.

    Note

    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.

  7. 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 How to: Obtain Code Coverage Data.

See Also

Tasks

How to: Obtain Code Coverage Data
Troubleshooting Generic Tests